From 0ed88a869a1d414dd067796c7b7a360970e247f8 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Fri, 17 Mar 2017 20:19:17 -0700 Subject: Update the name of the directory for benchmarks. (#152) --- benchmarks/pom.xml | 92 ++++++++++++++++ .../trace/HttpPropagationUtilBenchmark.java | 122 +++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 benchmarks/pom.xml create mode 100644 benchmarks/src/main/java/com/google/instrumentation/trace/HttpPropagationUtilBenchmark.java (limited to 'benchmarks') diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml new file mode 100644 index 00000000..92d0c7a9 --- /dev/null +++ b/benchmarks/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + census-benchmarks + + Census Java Benchmarks + https://github.com/google/instrumentation-java + + + com.google.census + census-parent + 0.1.0-SNAPSHOT + + + + + com.google.census + census-core + 0.1.0-SNAPSHOT + + + org.openjdk.jmh + jmh-core + 1.18 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.18 + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.2 + + + package + + shade + + + benchmarks + + + org.openjdk.jmh.Main + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + diff --git a/benchmarks/src/main/java/com/google/instrumentation/trace/HttpPropagationUtilBenchmark.java b/benchmarks/src/main/java/com/google/instrumentation/trace/HttpPropagationUtilBenchmark.java new file mode 100644 index 00000000..9214bc06 --- /dev/null +++ b/benchmarks/src/main/java/com/google/instrumentation/trace/HttpPropagationUtilBenchmark.java @@ -0,0 +1,122 @@ +/* + * Copyright 2017, Google Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.instrumentation.trace; + +import com.google.common.io.BaseEncoding; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; + +/** Benchmarks for {@link HttpPropagationUtil}. */ +@State(Scope.Benchmark) +public class HttpPropagationUtilBenchmark { + private static final byte[] traceIdBytes = + new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a'}; + private byte[] spanContextBytes; + private String spanContextString; + private static final TraceId traceId = TraceId.fromBytes(traceIdBytes); + private static final byte[] spanIdBytes = new byte[] {(byte) 0xFF, 0, 0, 0, 0, 0, 0, 0}; + private static final SpanId spanId = SpanId.fromBytes(spanIdBytes); + private static final byte[] traceOptionsBytes = new byte[] {0, 0, 0, 1}; + private static final TraceOptions traceOptions = TraceOptions.fromBytes(traceOptionsBytes); + private SpanContext spanContext; + private String spanContextStringHttp; + + @Setup + public void setUp() throws Exception { + spanContext = new SpanContext(traceId, spanId, traceOptions); + spanContextStringHttp = HttpPropagationUtil.toHttpHeaderValue(spanContext); + spanContextBytes = new byte[16 + 8 + 4]; + traceId.copyBytesTo(spanContextBytes, 0); + spanId.copyBytesTo(spanContextBytes, 16); + traceOptions.copyBytesTo(spanContextBytes, 24); + spanContextString = BaseEncoding.base16().lowerCase().encode(spanContextBytes); + } + + /** + * This benchmark attempts to measure performance of {@link + * HttpPropagationUtil#toHttpHeaderValue(SpanContext)}. + */ + @Benchmark + @BenchmarkMode(Mode.SampleTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public String toHttpHeaderValueSpanContext() { + return HttpPropagationUtil.toHttpHeaderValue(spanContext); + } + + /** + * This benchmark attempts to measure performance of {@link + * HttpPropagationUtil#fromHttpHeaderValue(CharSequence)}. + */ + @Benchmark + @BenchmarkMode(Mode.SampleTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public SpanContext fromHttpHeaderValueSpanContext() { + return HttpPropagationUtil.fromHttpHeaderValue(spanContextStringHttp); + } + + /** + * This benchmark attempts to measure performance of {@link + * HttpPropagationUtil#toHttpHeaderValue(SpanContext)} then {@link + * HttpPropagationUtil#fromHttpHeaderValue(CharSequence)}. + */ + @Benchmark + @BenchmarkMode(Mode.SampleTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public SpanContext toFromHttpFormatSpanContext() { + return HttpPropagationUtil.fromHttpHeaderValue( + HttpPropagationUtil.toHttpHeaderValue(spanContext)); + } + + /** + * This benchmark attempts to measure performance of base16 encoding from {@link + * HttpPropagationUtil#toHttpHeaderValue(SpanContext)}. + */ + @Benchmark + @BenchmarkMode(Mode.SampleTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public String base16EncodeSpanContext() { + return BaseEncoding.base16().lowerCase().encode(spanContextBytes); + } + + /** + * This benchmark attempts to measure performance of base16 decoding from {@link + * HttpPropagationUtil#fromHttpHeaderValue(CharSequence)}. + */ + @Benchmark + @BenchmarkMode(Mode.SampleTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public byte[] base16DecodeSpanContext() { + return BaseEncoding.base16().lowerCase().decode(spanContextString); + } + + /** + * This benchmark attempts to measure performance of base16 encoding and decoding from {@link + * HttpPropagationUtil#toHttpHeaderValue(SpanContext)} then {@link + * HttpPropagationUtil#fromHttpHeaderValue(CharSequence)}. + */ + @Benchmark + @BenchmarkMode(Mode.SampleTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public byte[] base16EncodeDecodeSpanContext() { + return BaseEncoding.base16() + .lowerCase() + .decode(BaseEncoding.base16().lowerCase().encode(spanContextBytes)); + } +} -- cgit v1.2.3