forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ExponentialHistogramIndexerBenchmark (open-telemetry#4989)
- Loading branch information
Showing
3 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...o/opentelemetry/sdk/metrics/internal/aggregator/ExponentialHistogramIndexerBenchmark.java
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,64 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.aggregator; | ||
|
||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
/** Measures runtime cost of computing bucket indexes for exponential histograms. */ | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Measurement(iterations = 5, time = 1) | ||
@Warmup(iterations = 5, time = 1) | ||
@Fork(1) | ||
public class ExponentialHistogramIndexerBenchmark { | ||
|
||
@State(Scope.Thread) | ||
public static class ThreadState { | ||
@Param(value = {"1", "0", "-1"}) | ||
int scale; | ||
|
||
private double[] values; | ||
private final AtomicLong valueIndex = new AtomicLong(); | ||
private ExponentialHistogramIndexer indexer; | ||
|
||
@Setup(Level.Trial) | ||
public final void setup() { | ||
Random random = new Random(); | ||
int numValues = 2000; | ||
values = new double[numValues]; | ||
for (int i = 0; i < numValues; i++) { | ||
values[i] = random.nextDouble() * 1000; | ||
} | ||
indexer = ExponentialHistogramIndexer.get(scale); | ||
} | ||
|
||
public void compute() { | ||
// Compute a number of samples | ||
for (int i = 0; i < 2000; i++) { | ||
indexer.computeIndex(values[(int) (valueIndex.incrementAndGet() % values.length)]); | ||
} | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void computeIndex(ThreadState threadState) { | ||
threadState.compute(); | ||
} | ||
} |
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