Initial commit
This commit is contained in:
10
benchmarks/CMakeLists.txt
Normal file
10
benchmarks/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
add_executable(benchmark_reference benchmark_reference.cpp)
|
||||
target_link_libraries(benchmark_reference PRIVATE trigdx)
|
||||
|
||||
add_executable(benchmark_lookup benchmark_lookup.cpp)
|
||||
target_link_libraries(benchmark_lookup PRIVATE trigdx)
|
||||
|
||||
if(USE_MKL)
|
||||
add_executable(benchmark_mkl benchmark_mkl.cpp)
|
||||
target_link_libraries(benchmark_mkl PRIVATE trigdx)
|
||||
endif()
|
||||
13
benchmarks/benchmark_lookup.cpp
Normal file
13
benchmarks/benchmark_lookup.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <trigdx/lookup.hpp>
|
||||
|
||||
#include "benchmark_utils.hpp"
|
||||
|
||||
int main() {
|
||||
benchmark_sinf<LookupBackend<16384>>();
|
||||
benchmark_cosf<LookupBackend<16384>>();
|
||||
benchmark_sincosf<LookupBackend<16384>>();
|
||||
|
||||
benchmark_sinf<LookupBackend<32768>>();
|
||||
benchmark_cosf<LookupBackend<32768>>();
|
||||
benchmark_sincosf<LookupBackend<32768>>();
|
||||
}
|
||||
9
benchmarks/benchmark_mkl.cpp
Normal file
9
benchmarks/benchmark_mkl.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <trigdx/mkl.hpp>
|
||||
|
||||
#include "benchmark_utils.hpp"
|
||||
|
||||
int main() {
|
||||
benchmark_sinf<MKLBackend>();
|
||||
benchmark_cosf<MKLBackend>();
|
||||
benchmark_sincosf<MKLBackend>();
|
||||
}
|
||||
9
benchmarks/benchmark_reference.cpp
Normal file
9
benchmarks/benchmark_reference.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <trigdx/reference.hpp>
|
||||
|
||||
#include "benchmark_utils.hpp"
|
||||
|
||||
int main() {
|
||||
benchmark_sinf<ReferenceBackend>();
|
||||
benchmark_cosf<ReferenceBackend>();
|
||||
benchmark_sincosf<ReferenceBackend>();
|
||||
}
|
||||
76
benchmarks/benchmark_utils.hpp
Normal file
76
benchmarks/benchmark_utils.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
const size_t N = 1e7;
|
||||
|
||||
inline void report(const std::string &name, double sec, double throughput) {
|
||||
std::ios state(nullptr);
|
||||
state.copyfmt(std::cout);
|
||||
std::cout << std::setw(7) << name << " -> ";
|
||||
std::cout << "time: ";
|
||||
std::cout << std::fixed << std::setprecision(3) << std::setfill('0');
|
||||
std::cout << sec << " s, ";
|
||||
std::cout << "throughput: " << throughput << " M elems/sec\n";
|
||||
std::cout.copyfmt(state);
|
||||
}
|
||||
|
||||
template <typename Backend> inline void benchmark_sinf() {
|
||||
std::vector<float> x(N), s(N);
|
||||
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
x[i] = (i % 360) * 0.0174533f; // degrees to radians
|
||||
|
||||
Backend backend;
|
||||
backend.init();
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
backend.compute_sinf(N, x.data(), s.data());
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
double sec = std::chrono::duration<double>(end - start).count();
|
||||
double throughput = N / sec / 1e6;
|
||||
|
||||
report("sinf", sec, throughput);
|
||||
}
|
||||
|
||||
template <typename Backend> inline void benchmark_cosf() {
|
||||
std::vector<float> x(N), c(N);
|
||||
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
x[i] = (i % 360) * 0.0174533f; // degrees to radians
|
||||
|
||||
Backend backend;
|
||||
backend.init();
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
backend.compute_cosf(N, x.data(), c.data());
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
double sec = std::chrono::duration<double>(end - start).count();
|
||||
double throughput = N / sec / 1e6;
|
||||
|
||||
report("cosf", sec, throughput);
|
||||
}
|
||||
|
||||
template <typename Backend> inline void benchmark_sincosf() {
|
||||
std::vector<float> x(N), s(N), c(N);
|
||||
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
x[i] = (i % 360) * 0.0174533f; // degrees to radians
|
||||
|
||||
Backend backend;
|
||||
backend.init();
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
backend.compute_sincosf(N, x.data(), s.data(), c.data());
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
double sec = std::chrono::duration<double>(end - start).count();
|
||||
double throughput = N / sec / 1e6;
|
||||
|
||||
report("sincosf", sec, throughput);
|
||||
}
|
||||
Reference in New Issue
Block a user