类org.openjdk.jmh.annotations.Benchmark源码实例Demo

下面列出了怎么用org.openjdk.jmh.annotations.Benchmark的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: presto   文件: BenchmarkGroupByHash.java
@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();
}
 
源代码2 项目: hadoop-ozone   文件: BenchmarkBlockDataToString.java
@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)));
  }
}
 
源代码3 项目: java   文件: NdArrayBenchmark.java
@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);
			})
	);
}
 
源代码4 项目: presto   文件: BenchmarkColumnReaders.java
@Benchmark
public Object readIntWithNull(IntegerWithNullBenchmarkData data)
        throws Exception
{
    try (OrcRecordReader recordReader = data.createRecordReader()) {
        return readFirstColumn(recordReader);
    }
}
 
源代码5 项目: perfmark   文件: VolatileGeneratorBenchmark.java
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@GroupThreads(3)
public long racyGetAndSetAndGetGeneration() {
  long oldGeneration = generator.getGeneration();
  generator.setGeneration(oldGeneration + 1);
  return generator.getGeneration();
}
 
源代码6 项目: java   文件: TensorBenchmark.java
@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);
}
 
源代码7 项目: netty-4.1.22   文件: AsciiStringBenchmark.java
@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;
}
 
源代码8 项目: netty-4.1.22   文件: ByteBufAllocatorBenchmark.java
@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);
}
 
源代码9 项目: hadoop-ozone   文件: BenchmarkChunkManager.java
@Benchmark
public void writeMultipleFiles(BenchmarkState state, Blackhole sink)
    throws StorageContainerException {

  ChunkManager chunkManager = new FilePerChunkStrategy(true, null);
  benchmark(chunkManager, FILE_PER_CHUNK, state, sink);
}
 
源代码10 项目: netty-4.1.22   文件: NetUtilBenchmark.java
@Benchmark
public void useIsValidIpv4() {
    for (String host : invalidIpV4Hosts.keySet()) {
        if (NetUtil.isValidIpV4Address(host)) {
            throw new RuntimeException("error");
        }
    }
}
 
源代码11 项目: FHIR   文件: FHIRValueSetBenchmarks.java
@Benchmark
public boolean lookupInList(FHIRValueSetState state) throws Exception {
    for (ValueSet.Expansion.Contains concept : state.valueSet.getExpansion().getContains()) {
        if (state.concept.getCode().equals(concept.getCode()) && state.concept.getSystem().equals(concept.getSystem())) {
            return true;
        }
    }
    return false;
}
 
源代码12 项目: hadoop-ozone   文件: BenchmarkBlockDataToString.java
@Benchmark
public void usingToStringBuilderDefaultCapacity(
    BenchmarkBlockDataToString state, Blackhole sink) {
  for (int i = 0; i < state.count; i++) {
    BlockData item = state.data.get(i);
    String str = new ToStringBuilder(item, ToStringStyle.NO_CLASS_NAME_STYLE)
        .append("blockId", item.getBlockID().toString())
        .append("size", item.getSize())
        .toString();
    sink.consume(str);
    Preconditions.checkArgument(str.equals(state.values.get(i)));
  }
}
 
源代码13 项目: presto   文件: BenchmarkLongBitPacker.java
@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;
}
 
源代码14 项目: grpc-nebula-java   文件: AttachDetachBenchmark.java
/**
 * 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);
  }
}
 
@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);
}
 
源代码16 项目: grpc-nebula-java   文件: InboundHeadersBenchmark.java
/**
 *  Checkstyle.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void grpcHeaders_clientHandler(Blackhole bh) {
  clientHandler(bh, new GrpcHttp2ResponseHeaders(2));
}
 
源代码17 项目: presto   文件: BenchmarkMapConcat.java
@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()));
}
 
/** 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;
}
 
@Benchmark
public int fastThreadLocal() {
    int result = 0;
    for (FastThreadLocal<Integer> i: fastThreadLocals) {
        result += i.get();
    }
    return result;
}
 
/**
 * 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);
}
 
源代码21 项目: presto   文件: BenchmarkBigIntOperators.java
@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;
}
 
源代码22 项目: grpc-nebula-java   文件: CallOptionsBenchmark.java
/**
 * 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;
}
 
源代码23 项目: presto   文件: BenchmarkCPUCounters.java
@Benchmark
@OperationsPerInvocation(ITERATIONS)
public void nanoTime(Blackhole blackhole)
{
    for (int i = 0; i < ITERATIONS; i++) {
        blackhole.consume(System.nanoTime());
    }
}
 
源代码24 项目: presto   文件: BenchmarkInCodeGenerator.java
@Benchmark
public List<Optional<Page>> benchmark()
{
    return ImmutableList.copyOf(
            processor.process(
                    SESSION,
                    new DriverYieldSignal(),
                    newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()),
                    inputPage));
}
 
源代码25 项目: presto   文件: BenchmarkStringFunctions.java
@Benchmark
public Slice benchmarkSubstringStart(BenchmarkData data)
{
    Slice slice = data.getSlice();
    int length = data.getLength();
    return substring(slice, (length / 2) - 1);
}
 
源代码26 项目: presto   文件: BenchmarkMapSubscript.java
@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()));
}
 
源代码27 项目: netty-4.1.22   文件: ByteBufAllocatorBenchmark.java
@Benchmark
public void unpooledDirectAllocAndFree() {
    int idx = rand.nextInt(unpooledDirectBuffers.length);
    ByteBuf oldBuf = unpooledDirectBuffers[idx];
    if (oldBuf != null) {
        oldBuf.release();
    }
    unpooledDirectBuffers[idx] = unpooledAllocator.directBuffer(size);
}
 
源代码28 项目: mantis   文件: CompressionUtilsBenchmark.java
@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;
}
 
源代码29 项目: presto   文件: BenchmarkReferenceCountMap.java
@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;
}
 
源代码30 项目: presto   文件: BenchmarkBigIntOperators.java
@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;
}