Java Code Examples for org.openjdk.jmh.annotations.Benchmark
The following examples show how to use
org.openjdk.jmh.annotations.Benchmark.
These examples are extracted from open source projects.
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: presto Author: prestosql File: BenchmarkGroupByHash.java License: Apache License 2.0 | 6 votes |
@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 #2
Source Project: hadoop-ozone Author: apache File: BenchmarkBlockDataToString.java License: Apache License 2.0 | 6 votes |
@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 #3
Source Project: java Author: tensorflow File: NdArrayBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #4
Source Project: presto Author: prestosql File: BenchmarkColumnReaders.java License: Apache License 2.0 | 5 votes |
@Benchmark public Object readIntWithNull(IntegerWithNullBenchmarkData data) throws Exception { try (OrcRecordReader recordReader = data.createRecordReader()) { return readFirstColumn(recordReader); } }
Example #5
Source Project: perfmark Author: perfmark File: VolatileGeneratorBenchmark.java License: Apache License 2.0 | 5 votes |
@Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @GroupThreads(3) public long racyGetAndSetAndGetGeneration() { long oldGeneration = generator.getGeneration(); generator.setGeneration(oldGeneration + 1); return generator.getGeneration(); }
Example #6
Source Project: java Author: tensorflow File: TensorBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #7
Source Project: netty-4.1.22 Author: tianheframe File: AsciiStringBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #8
Source Project: netty-4.1.22 Author: tianheframe File: ByteBufAllocatorBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #9
Source Project: hadoop-ozone Author: apache File: BenchmarkChunkManager.java License: Apache License 2.0 | 5 votes |
@Benchmark public void writeMultipleFiles(BenchmarkState state, Blackhole sink) throws StorageContainerException { ChunkManager chunkManager = new FilePerChunkStrategy(true, null); benchmark(chunkManager, FILE_PER_CHUNK, state, sink); }
Example #10
Source Project: netty-4.1.22 Author: tianheframe File: NetUtilBenchmark.java License: Apache License 2.0 | 5 votes |
@Benchmark public void useIsValidIpv4() { for (String host : invalidIpV4Hosts.keySet()) { if (NetUtil.isValidIpV4Address(host)) { throw new RuntimeException("error"); } } }
Example #11
Source Project: FHIR Author: IBM File: FHIRValueSetBenchmarks.java License: Apache License 2.0 | 5 votes |
@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; }
Example #12
Source Project: hadoop-ozone Author: apache File: BenchmarkBlockDataToString.java License: Apache License 2.0 | 5 votes |
@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))); } }
Example #13
Source Project: presto Author: prestosql File: BenchmarkLongBitPacker.java License: Apache License 2.0 | 5 votes |
@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 #14
Source Project: grpc-nebula-java Author: grpc-nebula File: AttachDetachBenchmark.java License: Apache License 2.0 | 5 votes |
/** * 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 #15
Source Project: opentelemetry-java Author: open-telemetry File: DoubleMinMaxSumCountBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #16
Source Project: grpc-nebula-java Author: grpc-nebula File: InboundHeadersBenchmark.java License: Apache License 2.0 | 5 votes |
/** * Checkstyle. */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void grpcHeaders_clientHandler(Blackhole bh) { clientHandler(bh, new GrpcHttp2ResponseHeaders(2)); }
Example #17
Source Project: presto Author: prestosql File: BenchmarkMapConcat.java License: Apache License 2.0 | 5 votes |
@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 #18
Source Project: opentelemetry-java Author: open-telemetry File: HttpTraceContextInjectBenchmark.java License: Apache License 2.0 | 5 votes |
/** 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 #19
Source Project: netty-4.1.22 Author: tianheframe File: FastThreadLocalSlowPathBenchmark.java License: Apache License 2.0 | 5 votes |
@Benchmark public int fastThreadLocal() { int result = 0; for (FastThreadLocal<Integer> i: fastThreadLocals) { result += i.get(); } return result; }
Example #20
Source Project: grpc-nebula-java Author: grpc-nebula File: StreamingPingPongsPerSecondBenchmark.java License: Apache License 2.0 | 5 votes |
/** * 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 #21
Source Project: presto Author: prestosql File: BenchmarkBigIntOperators.java License: Apache License 2.0 | 5 votes |
@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 #22
Source Project: grpc-nebula-java Author: grpc-nebula File: CallOptionsBenchmark.java License: Apache License 2.0 | 5 votes |
/** * 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 #23
Source Project: presto Author: prestosql File: BenchmarkCPUCounters.java License: Apache License 2.0 | 5 votes |
@Benchmark @OperationsPerInvocation(ITERATIONS) public void nanoTime(Blackhole blackhole) { for (int i = 0; i < ITERATIONS; i++) { blackhole.consume(System.nanoTime()); } }
Example #24
Source Project: presto Author: prestosql File: BenchmarkInCodeGenerator.java License: Apache License 2.0 | 5 votes |
@Benchmark public List<Optional<Page>> benchmark() { return ImmutableList.copyOf( processor.process( SESSION, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), inputPage)); }
Example #25
Source Project: presto Author: prestosql File: BenchmarkStringFunctions.java License: Apache License 2.0 | 5 votes |
@Benchmark public Slice benchmarkSubstringStart(BenchmarkData data) { Slice slice = data.getSlice(); int length = data.getLength(); return substring(slice, (length / 2) - 1); }
Example #26
Source Project: presto Author: prestosql File: BenchmarkMapSubscript.java License: Apache License 2.0 | 5 votes |
@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 #27
Source Project: netty-4.1.22 Author: tianheframe File: ByteBufAllocatorBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #28
Source Project: mantis Author: Netflix File: CompressionUtilsBenchmark.java License: Apache License 2.0 | 5 votes |
@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 #29
Source Project: presto Author: prestosql File: BenchmarkReferenceCountMap.java License: Apache License 2.0 | 5 votes |
@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 #30
Source Project: presto Author: prestosql File: BenchmarkBigIntOperators.java License: Apache License 2.0 | 5 votes |
@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; }