org.openjdk.jmh.annotations.Benchmark Java Examples

The following examples show how to use org.openjdk.jmh.annotations.Benchmark. 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 File: BenchmarkBlockDataToString.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Benchmark
public void usingInlineStringBuilder(
    BenchmarkBlockDataToString state, Blackhole sink) {
  for (int i = 0; i < state.count; i++) {
    BlockData item = state.data.get(i);
    BlockID blockID = item.getBlockID();
    ContainerBlockID containerBlockID = blockID.getContainerBlockID();
    String str = new StringBuilder(capacity)
        .append("[")
        .append("blockId=")
        .append("conID: ")
        .append(containerBlockID.getContainerID())
        .append(" locID: ")
        .append(containerBlockID.getLocalID())
        .append(" bcsId: ")
        .append(blockID.getBlockCommitSequenceId())
        .append(",size=")
        .append(item.getSize())
        .append("]")
        .toString();
    sink.consume(str);
    Preconditions.checkArgument(str.equals(state.values.get(i)));
  }
}
 
Example #2
Source File: BenchmarkGroupByHash.java    From presto with Apache License 2.0 6 votes vote down vote up
@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object bigintGroupByHash(SingleChannelBenchmarkData data)
{
    GroupByHash groupByHash = new BigintGroupByHash(0, data.getHashEnabled(), EXPECTED_SIZE, NOOP);
    data.getPages().forEach(p -> groupByHash.addPage(p).process());

    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(groupId, pageBuilder, 0);
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pageBuilder.build();
}
 
Example #3
Source File: BenchmarkReferenceCountMap.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(NUMBER_OF_ENTRIES)
public ReferenceCountMap benchmarkInserts(Data data)
{
    ReferenceCountMap map = new ReferenceCountMap();
    for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
        map.incrementAndGet(data.slices[i]);
        map.incrementAndGet(data.slices[i].getBase());
    }
    return map;
}
 
Example #4
Source File: BenchmarkLongBitPacker.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Object optimizedLength1(BenchmarkData data)
        throws Exception
{
    data.input.setPosition(0);
    data.packer.unpack(data.buffer, 0, 1, data.bits, data.input);
    return data.buffer;
}
 
Example #5
Source File: BenchmarkColumnReaders.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Object readIntWithNull(IntegerWithNullBenchmarkData data)
        throws Exception
{
    try (OrcRecordReader recordReader = data.createRecordReader()) {
        return readFirstColumn(recordReader);
    }
}
 
Example #6
Source File: DefaultTracerBenchmarks.java    From opentelemetry-java with 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 #7
Source File: VolatileGeneratorBenchmark.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(3)
public long racyGetAndSetAndGetGeneration() {
  long oldGeneration = generator.getGeneration();
  generator.setGeneration(oldGeneration + 1);
  return generator.getGeneration();
}
 
Example #8
Source File: SymSpellIndexBenchMark.java    From customized-symspell with MIT License 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Measurement(iterations = 1, time = 10, timeUnit = TimeUnit.SECONDS)
public void searchBenchmark() throws SpellCheckException, IOException, InterruptedException {
  indexData(dataFile, spellChecker.getDataHolder());
  System.out.println(" DataHolder Indexed Size " + spellChecker.getDataHolder().getSize());
  Thread.sleep(10000);
}
 
Example #9
Source File: BenchmarkLongBitPacker.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(2)
public Object baselineLength2(BenchmarkData data)
        throws Exception
{
    data.input.setPosition(0);
    unpackGeneric(data.buffer, 0, 2, data.bits, data.input);
    return data.buffer;
}
 
Example #10
Source File: AsciiStringBenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Benchmark
public int hashCodeBenchCharSequenceOld() {
    int h = 0;
    for (int i = 0; i < string.length(); ++i) {
        // masking with 0x1F reduces the number of overall bits that impact the hash code but makes the hash
        // code the same regardless of character case (upper case or lower case hash is the same).
        h = h * 31 + (string.charAt(i) & 0x1F);
    }
    return h;
}
 
Example #11
Source File: TensorBenchmark.java    From java with Apache License 2.0 5 votes vote down vote up
@Benchmark
@Measurement(batchSize = 1000)
public void initTensorByFlatArray() {
  IntDataBuffer data = DataBuffers.of(
      0, 0, 0,
      0, 0, 1,
      0, 0, 2,
      0, 1, 0,
      0, 1, 1,
      0, 1, 2,
      0, 2, 0,
      0, 2, 1,
      0, 2, 2,
      1, 0, 0,
      1, 0, 1,
      1, 0, 2,
      1, 1, 0,
      1, 1, 1,
      1, 1, 2,
      1, 2, 0,
      1, 2, 1,
      1, 2, 2,
      2, 0, 0,
      2, 0, 1,
      2, 0, 2,
      2, 1, 0,
      2, 1, 1,
      2, 1, 2,
      2, 2, 0,
      2, 2, 1,
      2, 2, 2
  );
  TInt32.tensorOf(Shape.of(3, 3, 3, 3), data);
}
 
Example #12
Source File: ByteBufAllocatorBenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void defaultPooledDirectAllocAndFree() {
    int idx = rand.nextInt(defaultPooledDirectBuffers.length);
    ByteBuf oldBuf = defaultPooledDirectBuffers[idx];
    if (oldBuf != null) {
        oldBuf.release();
    }
    defaultPooledDirectBuffers[idx] = PooledByteBufAllocator.DEFAULT.directBuffer(size);
}
 
Example #13
Source File: BenchmarkBigIntOperators.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Object overflowChecksAdd()
{
    long result = 0;
    result += BigintOperators.add(leftOperand0, rightOperand0);
    result += BigintOperators.add(leftOperand1, rightOperand0);
    result += BigintOperators.add(leftOperand2, rightOperand0);
    result += BigintOperators.add(leftOperand3, rightOperand0);
    result += BigintOperators.add(leftOperand4, rightOperand0);
    result += BigintOperators.add(leftOperand0, rightOperand1);
    result += BigintOperators.add(leftOperand1, rightOperand1);
    result += BigintOperators.add(leftOperand2, rightOperand1);
    result += BigintOperators.add(leftOperand3, rightOperand1);
    result += BigintOperators.add(leftOperand4, rightOperand1);
    result += BigintOperators.add(leftOperand0, rightOperand2);
    result += BigintOperators.add(leftOperand1, rightOperand2);
    result += BigintOperators.add(leftOperand2, rightOperand2);
    result += BigintOperators.add(leftOperand3, rightOperand2);
    result += BigintOperators.add(leftOperand4, rightOperand2);
    result += BigintOperators.add(leftOperand0, rightOperand3);
    result += BigintOperators.add(leftOperand1, rightOperand3);
    result += BigintOperators.add(leftOperand2, rightOperand3);
    result += BigintOperators.add(leftOperand3, rightOperand3);
    result += BigintOperators.add(leftOperand4, rightOperand3);
    result += BigintOperators.add(leftOperand0, rightOperand4);
    result += BigintOperators.add(leftOperand1, rightOperand4);
    result += BigintOperators.add(leftOperand2, rightOperand4);
    result += BigintOperators.add(leftOperand3, rightOperand4);
    result += BigintOperators.add(leftOperand4, rightOperand4);
    return result;
}
 
Example #14
Source File: BenchmarkLongBitPacker.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(3)
public Object baselineLength3(BenchmarkData data)
        throws Exception
{
    data.input.setPosition(0);
    unpackGeneric(data.buffer, 0, 3, data.bits, data.input);
    return data.buffer;
}
 
Example #15
Source File: AttachDetachBenchmark.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Javadoc comment.
 */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(6)
public int attachDetach() {
  Context old = cu.attach();
  try {
    return key.get();
  } finally {
    Context.current().detach(old);
  }
}
 
Example #16
Source File: NdArrayBenchmark.java    From java with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void writeAllPixelsByIndex() {
	batches.elements(0).forEach(batch ->
			pixels.elements(0).forEachIndexed((coords, pixel) -> {
			  long pixelIndex = coords[0];
				batch
						.setFloat(pixel.getFloat(0), 0, pixelIndex)
						.setFloat(pixel.getFloat(1), 1, pixelIndex)
						.setFloat(pixel.getFloat(2), 2, pixelIndex);
			})
	);
}
 
Example #17
Source File: DoubleMinMaxSumCountBenchmark.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Benchmark
@Fork(1)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 10, time = 1)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Threads(value = 1)
public void aggregate_1Threads() {
  aggregator.recordDouble(100.0056);
}
 
Example #18
Source File: InboundHeadersBenchmark.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 *  Checkstyle.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void grpcHeaders_clientHandler(Blackhole bh) {
  clientHandler(bh, new GrpcHttp2ResponseHeaders(2));
}
 
Example #19
Source File: CompressionUtilsBenchmark.java    From mantis with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MINUTES)
@Warmup(iterations = 10, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 50, time = 3, timeUnit = TimeUnit.SECONDS)
@Threads(1)
public void testBasicStringSplit(Blackhole blackhole, MyState state) throws IOException {
    BufferedReader bf = new BufferedReader(new StringReader(state.eventListStr));

    StringBuilder sb = new StringBuilder();
    String line;
    List<String> msseList = new ArrayList<>();
    int dollarCnt = 0;
    while ((line = bf.readLine()) != null) {
        for (int i = 0; i < line.length(); i++) {
            if (dollarCnt == 3) {
                msseList.add(sb.toString());
                dollarCnt = 0;
                sb = new StringBuilder();
            }
            if (line.charAt(i) != '$') {
                sb.append(line.charAt(i));
            } else {
                dollarCnt++;
            }
        }

    }
    blackhole.consume(msseList);
    //blackhole.consume(state.eventListStr.split("$$"));
    //state.sum = state.a + state.b;
}
 
Example #20
Source File: ByteBufAllocatorBenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void unpooledDirectAllocAndFree() {
    int idx = rand.nextInt(unpooledDirectBuffers.length);
    ByteBuf oldBuf = unpooledDirectBuffers[idx];
    if (oldBuf != null) {
        oldBuf.release();
    }
    unpooledDirectBuffers[idx] = unpooledAllocator.directBuffer(size);
}
 
Example #21
Source File: BenchmarkMapConcat.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(POSITIONS)
public List<Optional<Page>> mapConcat(BenchmarkData data)
{
    return ImmutableList.copyOf(
            data.getPageProcessor().process(
                    SESSION,
                    new DriverYieldSignal(),
                    newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()),
                    data.getPage()));
}
 
Example #22
Source File: BenchmarkMapSubscript.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(POSITIONS)
public List<Optional<Page>> mapSubscript(BenchmarkData data)
{
    return ImmutableList.copyOf(
            data.getPageProcessor().process(
                    SESSION,
                    new DriverYieldSignal(),
                    newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()),
                    data.getPage()));
}
 
Example #23
Source File: HttpTraceContextInjectBenchmark.java    From opentelemetry-java with 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 #24
Source File: FastThreadLocalSlowPathBenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Benchmark
public int fastThreadLocal() {
    int result = 0;
    for (FastThreadLocal<Integer> i: fastThreadLocals) {
        result += i.get();
    }
    return result;
}
 
Example #25
Source File: BenchmarkStringFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Slice benchmarkSubstringStart(BenchmarkData data)
{
    Slice slice = data.getSlice();
    int length = data.getLength();
    return substring(slice, (length / 2) - 1);
}
 
Example #26
Source File: StreamingPingPongsPerSecondBenchmark.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Measure throughput of unary calls. The calls are already running, we just observe a counter
 * of received responses.
 */
@Benchmark
public void pingPong(AdditionalCounters counters) throws Exception {
  record.set(true);
  // No need to do anything, just sleep here.
  Thread.sleep(1001);
  record.set(false);
}
 
Example #27
Source File: BenchmarkBigIntOperators.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Object overflowChecksSubtract()
{
    long result = 0;
    result += BigintOperators.subtract(leftOperand0, rightOperand0);
    result += BigintOperators.subtract(leftOperand1, rightOperand0);
    result += BigintOperators.subtract(leftOperand2, rightOperand0);
    result += BigintOperators.subtract(leftOperand3, rightOperand0);
    result += BigintOperators.subtract(leftOperand4, rightOperand0);
    result += BigintOperators.subtract(leftOperand0, rightOperand1);
    result += BigintOperators.subtract(leftOperand1, rightOperand1);
    result += BigintOperators.subtract(leftOperand2, rightOperand1);
    result += BigintOperators.subtract(leftOperand3, rightOperand1);
    result += BigintOperators.subtract(leftOperand4, rightOperand1);
    result += BigintOperators.subtract(leftOperand0, rightOperand2);
    result += BigintOperators.subtract(leftOperand1, rightOperand2);
    result += BigintOperators.subtract(leftOperand2, rightOperand2);
    result += BigintOperators.subtract(leftOperand3, rightOperand2);
    result += BigintOperators.subtract(leftOperand4, rightOperand2);
    result += BigintOperators.subtract(leftOperand0, rightOperand3);
    result += BigintOperators.subtract(leftOperand1, rightOperand3);
    result += BigintOperators.subtract(leftOperand2, rightOperand3);
    result += BigintOperators.subtract(leftOperand3, rightOperand3);
    result += BigintOperators.subtract(leftOperand4, rightOperand3);
    result += BigintOperators.subtract(leftOperand0, rightOperand4);
    result += BigintOperators.subtract(leftOperand1, rightOperand4);
    result += BigintOperators.subtract(leftOperand2, rightOperand4);
    result += BigintOperators.subtract(leftOperand3, rightOperand4);
    result += BigintOperators.subtract(leftOperand4, rightOperand4);
    return result;
}
 
Example #28
Source File: BenchmarkInCodeGenerator.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
public List<Optional<Page>> benchmark()
{
    return ImmutableList.copyOf(
            processor.process(
                    SESSION,
                    new DriverYieldSignal(),
                    newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()),
                    inputPage));
}
 
Example #29
Source File: CallOptionsBenchmark.java    From grpc-nebula-java with 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 #30
Source File: BenchmarkCPUCounters.java    From presto with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(ITERATIONS)
public void nanoTime(Blackhole blackhole)
{
    for (int i = 0; i < ITERATIONS; i++) {
        blackhole.consume(System.nanoTime());
    }
}