sfizz/benchmarks/BM_fill.cpp

64 lines
1.9 KiB
C++
Raw Normal View History

2019-08-21 01:00:07 +02:00
#include <benchmark/benchmark.h>
#include "../sources/SIMDHelpers.h"
#include "../sources/Buffer.h"
#include <algorithm>
#include <random>
#include <numeric>
static void Dummy(benchmark::State& state) {
Buffer<float> buffer (state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state) {
auto fillValue = dist(gen);
benchmark::DoNotOptimize(fillValue);
}
}
2019-08-22 12:05:28 +02:00
static void FillScalar(benchmark::State& state) {
2019-08-21 01:00:07 +02:00
Buffer<float> buffer (state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state) {
2019-08-21 23:00:06 +02:00
fill<float, false>(absl::MakeSpan(buffer), dist(gen));
}
}
2019-08-22 12:05:28 +02:00
static void FillScalar_unaligned(benchmark::State& state) {
2019-08-21 23:00:06 +02:00
Buffer<float> buffer (state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state) {
fill<float, false>(absl::MakeSpan(buffer).subspan(1), dist(gen));
2019-08-21 01:00:07 +02:00
}
}
2019-08-22 12:05:28 +02:00
static void FillSIMD(benchmark::State& state) {
2019-08-21 01:00:07 +02:00
Buffer<float> buffer (state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state) {
2019-08-21 23:00:06 +02:00
fill<float, true>(absl::MakeSpan(buffer), dist(gen));
}
}
2019-08-22 12:05:28 +02:00
static void FillSIMD_unaligned(benchmark::State& state) {
2019-08-21 23:00:06 +02:00
Buffer<float> buffer (state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state) {
fill<float, true>(absl::MakeSpan(buffer).subspan(1), dist(gen));
2019-08-21 01:00:07 +02:00
}
}
BENCHMARK(Dummy)->Range((2<<6), (2<<16));
2019-08-22 12:05:28 +02:00
BENCHMARK(FillScalar)->Range((2<<6), (2<<16));
BENCHMARK(FillSIMD)->Range((2<<6), (2<<16));
BENCHMARK(FillScalar_unaligned)->Range((2<<6), (2<<16));
BENCHMARK(FillSIMD_unaligned)->Range((2<<6), (2<<16));
2019-08-21 01:00:07 +02:00
BENCHMARK_MAIN();