org.openjdk.jmh.annotations.BenchmarkMode Java Examples

The following examples show how to use org.openjdk.jmh.annotations.BenchmarkMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: opentelemetry-java   Author: open-telemetry   File: HttpTraceContextExtractBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
/** Benchmark for measuring HttpTraceContext extract. */
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@Fork(1)
@Measurement(iterations = 15, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1)
@OperationsPerInvocation(COUNT)
@Nullable
public Context measureExtract() {
  Context result = null;
  for (int i = 0; i < COUNT; i++) {
    result = httpTraceContext.extract(Context.ROOT, carriers.get(i), getter);
  }
  return result;
}
 
Example #2
Source Project: grpc-nebula-java   Author: grpc-nebula   File: WriteBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/** Perform the write operation. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Context doWrite(ContextState state, Blackhole bh) {
  return state.context.withValues(
      state.key1, state.val,
      state.key2, state.val,
      state.key3, state.val,
      state.key4, state.val);
}
 
Example #3
Source Project: grpc-nebula-java   Author: grpc-nebula   File: ReadBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/** Perform the read operation. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void testContextLookup(ContextState state, Blackhole bh) {
  for (Context.Key<?> key : state.keys) {
    for (Context ctx : state.contexts) {
      bh.consume(key.get(ctx));
    }
  }
}
 
Example #4
Source Project: grpc-nebula-java   Author: grpc-nebula   File: InboundHeadersBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checkstyle.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void grpcHeaders_serverHandler(Blackhole bh) {
  serverHandler(bh, new GrpcHttp2RequestHeaders(4));
}
 
Example #5
Source Project: netty-4.1.22   Author: tianheframe   File: HeadersBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public void http2Remove(Blackhole bh) {
    for (AsciiString name : http2Names) {
        bh.consume(http2Headers.remove(name));
    }
}
 
Example #6
Source Project: grpc-nebula-java   Author: grpc-nebula   File: OutboundHeadersBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This will encode the random metadata fields, and repeatedly lookup the default other headers.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public ByteBuf encodeClientHeaders() throws Exception {
  scratchBuffer.clear();
  Http2Headers headers =
      Utils.convertClientHeaders(metadata, scheme, defaultPath, authority, Utils.HTTP_METHOD,
          userAgent);
  headersEncoder.encodeHeaders(1, headers, scratchBuffer);
  return scratchBuffer;
}
 
Example #7
Source Project: grpc-nebula-java   Author: grpc-nebula   File: MethodDescriptorBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/** Foo bar. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public AsciiString old() {
  return new AsciiString("/" + method.getFullMethodName());
}
 
Example #8
Source Project: grpc-nebula-java   Author: grpc-nebula   File: MethodDescriptorBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/** Foo bar. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public AsciiString direct() {
  return new AsciiString(directBytes, false);
}
 
Example #9
Source Project: grpc-nebula-java   Author: grpc-nebula   File: DecompressorRegistryBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Javadoc comment.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public byte[][] marshalOld() {
  Metadata m = new Metadata();
  m.put(
      GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY,
      InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(reg));
  return TransportFrameUtil.toHttp2Headers(m);
}
 
Example #10
Source Project: perfmark   Author: perfmark   File: MethodHandleGeneratorBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public long getAndSetAndGetGeneration() {
  long oldGeneration = generator.getGeneration();
  generator.setGeneration(oldGeneration + 1);
  return generator.getGeneration();
}
 
Example #11
Source Project: grpc-nebula-java   Author: grpc-nebula   File: CallOptionsBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adding custom call options, overwritting existing keys.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public CallOptions withOptionDuplicates() {
  CallOptions opts = allOpts;
  for (int i = 1; i < shuffledCustomOptions.size(); i++) {
    opts = opts.withOption(shuffledCustomOptions.get(i), "value2");
  }
  return opts;
}
 
Example #12
Source Project: opentelemetry-java   Author: open-telemetry   File: DefaultTracerBenchmarks.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@Fork(1)
@Measurement(iterations = 15, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1)
public void measureSpanBuilding() {
  span = tracer.spanBuilder("span").startSpan();
}
 
Example #13
Source Project: grpc-nebula-java   Author: grpc-nebula   File: SerializingExecutorBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Queue many runnables, to better see queuing/consumption cost instead of just context switch.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void manyRunnables() throws Exception {
  incrRunnable.val = 0;
  for (int i = 0; i < 500; i++) {
    executor.execute(incrRunnable);
  }
  executor.execute(phaserRunnable);
  phaser.arriveAndAwaitAdvance();
  if (incrRunnable.val != 500) {
    throw new AssertionError();
  }
}
 
Example #14
Source Project: netty-4.1.22   Author: tianheframe   File: HpackDecoderULE128Benchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int decodeMaxInt() throws Http2Exception {
    int v = decodeULE128(intMaxBuf, 0);
    intMaxBuf.readerIndex(0);
    return v;
}
 
Example #15
Source Project: grpc-nebula-java   Author: grpc-nebula   File: StatsTraceContextBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Javadoc comment.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public StatsTraceContext newClientContext() {
  return StatsTraceContext.newClientContext(CallOptions.DEFAULT, emptyMetadata);
}
 
Example #16
Source Project: opentelemetry-java   Author: open-telemetry   File: DefaultTracerBenchmarks.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@Fork(1)
@Measurement(iterations = 15, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1)
public void measureGetCurrentSpan() {
  tracer.getCurrentSpan();
}
 
Example #17
Source Project: grpc-nebula-java   Author: grpc-nebula   File: StatusBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Javadoc comment.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public String messageDecodePlain() {
  return Status.MESSAGE_KEY.parseBytes(
      "Unexpected RST in stream".getBytes(Charset.forName("US-ASCII")));
}
 
Example #18
Source Project: netty-4.1.22   Author: tianheframe   File: ReadOnlyHttp2HeadersBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int defaultTrailers() {
    Http2Headers headers = new DefaultHttp2Headers(false);
    for (int i = 0; i < headerCount; ++i) {
        headers.add(headerNames[i], headerValues[i]);
    }
    return iterate(headers);
}
 
Example #19
Source Project: grpc-nebula-java   Author: grpc-nebula   File: StatusBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Javadoc comment.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Status codeDecode() {
  return Status.CODE_KEY.parseBytes("15".getBytes(Charset.forName("US-ASCII")));
}
 
Example #20
Source Project: customized-symspell   Author: MighTguY   File: SymSpellSearchBenchMark.java    License: MIT License 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Measurement(iterations = 1)
public void searchBenchmark() throws SpellCheckException {
  for (String query : queries) {
    totalMatches += spellChecker.lookup(query, Verbosity.valueOf(verbosity), maxEditDistance)
        .size();
  }
}
 
Example #21
Source Project: sofa-jraft   Author: sofastack   File: RawKVPutBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void put() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    byte[] key = BytesUtil.writeUtf8("benchmark_" + random.nextInt(KEY_COUNT));
    super.kvStore.put(key, VALUE_BYTES, null);
}
 
Example #22
Source Project: opentelemetry-java   Author: open-telemetry   File: HttpTraceContextInjectBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
/** Benchmark for measuring inject with default trace state and sampled trace options. */
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@Fork(1)
@Measurement(iterations = 15, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1)
@OperationsPerInvocation(COUNT)
public Map<String, String> measureInject() {
  for (int i = 0; i < COUNT; i++) {
    httpTraceContext.inject(contexts.get(i), carrier, setter);
  }
  return carrier;
}
 
Example #23
Source Project: sofa-jraft   Author: sofastack   File: RheaKVPutBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void put() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    byte[] key = BytesUtil.writeUtf8("benchmark_" + random.nextInt(KEY_COUNT));
    this.kvStore.bPut(key, VALUE_BYTES);
}
 
Example #24
Source Project: sofa-jraft   Author: sofastack   File: VarIntsBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void int64() {
    byte[] bytes = new byte[8];
    putLong(bytes, 0, SMALL_VAL);
    getLong(bytes, 0);
}
 
Example #25
Source Project: netty-4.1.22   Author: tianheframe   File: HeadersBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public DefaultHttpHeaders httpPut() {
    DefaultHttpHeaders headers = new DefaultHttpHeaders(false);
    for (int i = 0; i < httpNames.length; i++) {
        headers.add(httpNames[i], httpValues[i]);
    }
    return headers;
}
 
Example #26
Source Project: netty-4.1.22   Author: tianheframe   File: HeadersBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public void http2Get(Blackhole bh) {
    for (AsciiString name : http2Names) {
        bh.consume(http2Headers.get(name));
    }
}
 
Example #27
Source Project: sofa-jraft   Author: sofastack   File: AsciiCodecBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void fastpathEncode() {
    // fast ptah
    AsciiStringUtil.unsafeEncode(PEER_STR);
}
 
Example #28
Source Project: netty-4.1.22   Author: tianheframe   File: HpackEncoderBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public void encode(Blackhole bh) throws Exception {
    HpackEncoder hpackEncoder = HpackUtilBenchmark.newTestEncoder();
    output.clear();
    hpackEncoder.encodeHeaders(3 /*randomly chosen*/, output, http2Headers, sensitivityDetector);
    bh.consume(output);
}
 
Example #29
Source Project: sofa-jraft   Author: sofastack   File: Utf8CodecBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("all")
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void defaultToUtf8Bytes() {
    Utils.getBytes(str);
}
 
Example #30
Source Project: opentelemetry-java   Author: open-telemetry   File: DefaultTracerBenchmarks.java    License: Apache License 2.0 5 votes vote down vote up
/** Benchmark just the scope lifecycle. */
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@Fork(1)
@Measurement(iterations = 15, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1)
public void measureScopeLifecycle() {
  try (io.opentelemetry.context.Scope ignored = tracer.withSpan(span)) {
    // no-op
  }
}