1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include <benchmark/benchmark.h>
#include <stdint.h>
#include <array>
#include <random>
#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h"
using namespace opentelemetry::sdk::metrics;
namespace
{
void BM_NewIndexer(benchmark::State &state)
{
std::array<int, 1000> batch;
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(1, 32);
while (state.KeepRunningBatch(static_cast<benchmark::IterationCount>(batch.size())))
{
state.PauseTiming();
for (auto &value : batch)
{
value = distribution(generator);
}
state.ResumeTiming();
for (const auto value : batch)
{
benchmark::DoNotOptimize(Base2ExponentialHistogramIndexer(value));
}
}
}
BENCHMARK(BM_NewIndexer);
void BM_ComputeIndex(benchmark::State &state)
{
std::array<double, 1000> batch;
std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(0, 1000);
Base2ExponentialHistogramIndexer indexer(static_cast<int32_t>(state.range(0)));
while (state.KeepRunningBatch(static_cast<benchmark::IterationCount>(batch.size())))
{
state.PauseTiming();
for (auto &value : batch)
{
value = distribution(generator);
}
state.ResumeTiming();
for (const auto value : batch)
{
benchmark::DoNotOptimize(indexer.ComputeIndex(value));
}
}
}
BENCHMARK(BM_ComputeIndex)->Arg(-1)->Arg(0)->Arg(1)->Arg(20);
} // namespace
BENCHMARK_MAIN();
|