-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d06887a
commit a1590f8
Showing
10 changed files
with
125 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <math_approx/math_approx.hpp> | ||
#include <benchmark/benchmark.h> | ||
|
||
static constexpr size_t N = 2000; | ||
const auto data = [] | ||
{ | ||
std::vector<float> x; | ||
x.resize (N, 0.0f); | ||
for (size_t i = 0; i < N; ++i) | ||
x[i] = -10.0f + 20.0f * (float) i / (float) N; | ||
return x; | ||
}(); | ||
|
||
#define TRIG_BENCH(name, func) \ | ||
void name (benchmark::State& state) \ | ||
{ \ | ||
for (auto _ : state) \ | ||
{ \ | ||
for (auto& x : data) \ | ||
{ \ | ||
auto y = func (x); \ | ||
benchmark::DoNotOptimize (y); \ | ||
} \ | ||
} \ | ||
} \ | ||
BENCHMARK (name); | ||
|
||
TRIG_BENCH (cos_std, std::cos) | ||
TRIG_BENCH (cos_approx9, math_approx::cos<9>) | ||
TRIG_BENCH (cos_approx7, math_approx::cos<7>) | ||
TRIG_BENCH (cos_approx5, math_approx::cos<5>) | ||
|
||
TRIG_BENCH (sin_std, std::sin) | ||
TRIG_BENCH (sin_approx9, math_approx::sin<9>) | ||
TRIG_BENCH (sin_approx7, math_approx::sin<7>) | ||
TRIG_BENCH (sin_approx5, math_approx::sin<5>) | ||
|
||
#define TRIG_SIMD_BENCH(name, func) \ | ||
void name (benchmark::State& state) \ | ||
{ \ | ||
for (auto _ : state) \ | ||
{ \ | ||
for (auto& x : data) \ | ||
{ \ | ||
auto y = func (xsimd::broadcast (x)); \ | ||
static_assert (std::is_same_v<xsimd::batch<float>, decltype(y)>); \ | ||
benchmark::DoNotOptimize (y); \ | ||
} \ | ||
} \ | ||
} \ | ||
BENCHMARK (name); | ||
|
||
TRIG_SIMD_BENCH (sin_xsimd, xsimd::sin) | ||
TRIG_SIMD_BENCH (sin_simd_approx9, math_approx::sin<9>) | ||
TRIG_SIMD_BENCH (sin_simd_approx7, math_approx::sin<7>) | ||
TRIG_SIMD_BENCH (sin_simd_approx5, math_approx::sin<5>) | ||
|
||
TRIG_SIMD_BENCH (cos_xsimd, xsimd::cos) | ||
TRIG_SIMD_BENCH (cos_simd_approx9, math_approx::cos<9>) | ||
TRIG_SIMD_BENCH (cos_simd_approx7, math_approx::cos<7>) | ||
TRIG_SIMD_BENCH (cos_simd_approx5, math_approx::cos<5>) | ||
|
||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters