sfizz/benchmarks/BM_ramp.cpp

138 lines
4.9 KiB
C++
Raw Permalink Normal View History

2020-01-25 10:04:31 +01:00
// SPDX-License-Identifier: BSD-2-Clause
2020-01-25 13:13:07 +01:00
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
2019-08-30 00:49:58 +02:00
2020-01-04 17:38:51 +01:00
#include "SIMDHelpers.h"
2019-08-22 12:05:28 +02:00
#include <benchmark/benchmark.h>
#include <random>
#include "Buffer.h"
2019-08-22 12:05:28 +02:00
static void Dummy(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
benchmark::DoNotOptimize(value);
}
}
static void LinearScalar(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::linearRamp, false);
2020-05-30 23:25:12 +02:00
sfz::linearRamp<float>(absl::MakeSpan(output), 0.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void LinearSIMD(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::linearRamp, true);
2020-05-30 23:25:12 +02:00
sfz::linearRamp<float>(absl::MakeSpan(output), 0.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void LinearScalarUnaligned(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::linearRamp, false);
2020-05-30 23:25:12 +02:00
sfz::linearRamp<float>(absl::MakeSpan(output).subspan(1), 0.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void LinearSIMDUnaligned(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::linearRamp, true);
2020-05-30 23:25:12 +02:00
sfz::linearRamp<float>(absl::MakeSpan(output).subspan(1), 0.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void MulScalar(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::multiplicativeRamp, false);
2020-05-30 23:25:12 +02:00
sfz::multiplicativeRamp<float>(absl::MakeSpan(output), 1.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void MulSIMD(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::multiplicativeRamp, true);
2020-05-30 23:25:12 +02:00
sfz::multiplicativeRamp<float>(absl::MakeSpan(output), 1.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void MulScalarUnaligned(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::multiplicativeRamp, false);
2020-05-30 23:25:12 +02:00
sfz::multiplicativeRamp<float>(absl::MakeSpan(output).subspan(1), 1.0f, value);
2019-08-22 12:05:28 +02:00
}
}
static void MulSIMDUnaligned(benchmark::State& state) {
sfz::Buffer<float> output(state.range(0));
2019-08-22 12:05:28 +02:00
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 1, 2 };
for (auto _ : state)
{
auto value = dist(gen);
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::multiplicativeRamp, true);
2020-05-30 23:25:12 +02:00
sfz::multiplicativeRamp<float>(absl::MakeSpan(output).subspan(1), 1.0f, value);
2019-08-22 12:05:28 +02:00
}
}
// Register the function as a benchmark
BENCHMARK(Dummy)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LinearScalar)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LinearSIMD)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LinearScalarUnaligned)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LinearSIMDUnaligned)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(MulScalar)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(MulSIMD)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(MulScalarUnaligned)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(MulSIMDUnaligned)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
2020-01-04 17:38:51 +01:00
BENCHMARK_MAIN();