#include #include #include #include #include #include #include "../sources/SIMDHelpers.h" class MyFixture : public benchmark::Fixture { public: void SetUp(const ::benchmark::State& state) { std::random_device rd { }; std::mt19937 gen { rd() }; std::uniform_real_distribution dist { 0.1, 1 }; source = std::vector(state.range(0)); result = std::vector(state.range(0)); std::generate(source.begin(), source.end(), [&]() { return dist(gen); }); } void TearDown(const ::benchmark::State& state [[maybe_unused]]) { } std::vector source; std::vector result; }; BENCHMARK_DEFINE_F(MyFixture, Dummy)(benchmark::State& state) { for (auto _ : state) { for (int i = 0; i < state.range(0); ++i) result[i] = source[i]; benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, StdExp)(benchmark::State& state) { for (auto _ : state) { for (int i = 0; i < state.range(0); ++i) result[i] = std::exp(source[i]); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, ScalarExp)(benchmark::State& state) { for (auto _ : state) { exp(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, SIMDExp)(benchmark::State& state) { for (auto _ : state) { exp(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, StdLog)(benchmark::State& state) { for (auto _ : state) { for (int i = 0; i < state.range(0); ++i) result[i] = std::log(source[i]); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, ScalarLog)(benchmark::State& state) { for (auto _ : state) { log(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, SIMDLog)(benchmark::State& state) { for (auto _ : state) { log(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, StdSin)(benchmark::State& state) { for (auto _ : state) { for (int i = 0; i < state.range(0); ++i) result[i] = std::sin(source[i]); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, ScalarSin)(benchmark::State& state) { for (auto _ : state) { sin(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, SIMDSin)(benchmark::State& state) { for (auto _ : state) { sin(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, StdCos)(benchmark::State& state) { for (auto _ : state) { for (int i = 0; i < state.range(0); ++i) result[i] = std::cos(source[i]); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, ScalarCos)(benchmark::State& state) { for (auto _ : state) { cos(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_DEFINE_F(MyFixture, SIMDCos)(benchmark::State& state) { for (auto _ : state) { cos(source, absl::MakeSpan(result)); benchmark::DoNotOptimize(result); } } BENCHMARK_REGISTER_F(MyFixture, Dummy)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, StdExp)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, ScalarExp)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, SIMDExp)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, StdLog)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, ScalarLog)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, SIMDLog)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, StdSin)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, ScalarSin)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, SIMDSin)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, StdCos)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, ScalarCos)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_REGISTER_F(MyFixture, SIMDCos)->RangeMultiplier(4)->Range(1 << 6, 1 << 10); BENCHMARK_MAIN();