-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] Add benchmark for base2 exponential histogram indexer (#2181)
- Loading branch information
Ruslan Nigmatullin
authored
Jun 7, 2023
1 parent
d980e8b
commit d233b9b
Showing
3 changed files
with
86 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc
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,65 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <array> | ||
#include <random> | ||
|
||
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(); |