File: base2_exponential_histogram_indexer_benchmark.cc

package info (click to toggle)
opentelemetry-cpp 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,744 kB
  • sloc: cpp: 79,029; sh: 1,640; makefile: 43; python: 31
file content (66 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (2)
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();