Java Code Examples for org.openjdk.jmh.infra.Blackhole

The following examples show how to use org.openjdk.jmh.infra.Blackhole. 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: hadoop-ozone   Author: apache   File: BenchMarkOzoneManager.java    License: Apache License 2.0 6 votes vote down vote up
@Threads(4)
@Benchmark
public void createAndCommitKeyBenchMark(BenchMarkOzoneManager state,
    Blackhole bh) throws IOException {
  String key = UUID.randomUUID().toString();
  OmKeyArgs omKeyArgs = new OmKeyArgs.Builder()
      .setVolumeName(volumeName)
      .setBucketName(bucketName)
      .setKeyName(key)
      .setDataSize(50)
      .setFactor(HddsProtos.ReplicationFactor.THREE)
      .setType(HddsProtos.ReplicationType.RATIS)
      .build();
  OpenKeySession openKeySession = state.om.openKey(omKeyArgs);
  state.om.allocateBlock(omKeyArgs, openKeySession.getId(),
      new ExcludeList());
}
 
Example #2
Source Project: hadoop-ozone   Author: apache   File: BenchmarkBlockDataToString.java    License: Apache License 2.0 6 votes vote down vote up
@Benchmark
public void usingSimpleStringBuilder(
    BenchmarkBlockDataToString state, Blackhole sink) {
  for (int i = 0; i < state.count; i++) {
    BlockData item = state.data.get(i);
    String str = new StringBuilder(capacity)
        .append("[")
        .append("blockId=")
        .append(item.getBlockID())
        .append(",size=")
        .append(item.getSize())
        .append("]")
        .toString();
    sink.consume(str);
    Preconditions.checkArgument(str.equals(state.values.get(i)));
  }
}
 
Example #3
Source Project: raptor   Author: geekshop   File: OkhttpRaptorServerBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
@Benchmark
public void test(Blackhole bh) {
    String body = "{\"name\":\"ppdai\"}";
    String url = "http://localhost:" + port + "/raptor/com.ppdai.framework.raptor.proto.Simple/sayHello";

    Request request = new Request.Builder()
            .url(url)
            .header("connection", "Keep-Alive")
            .post(RequestBody.create(MediaType.parse(ContentType.APPLICATION_JSON.toString()), body.getBytes()))
            .build();
    String responseBody;
    try (Response response = client.newCall(request).execute()) {
        responseBody = new String(response.body().bytes(), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException("error", e);
    }
    bh.consume(responseBody);
}
 
Example #4
Source Project: iceberg   Author: apache   File: SparkParquetReadersFlatDataBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
@Benchmark
@Threads(1)
public void readUsingIcebergReaderUnsafe(Blackhole blackhole) throws IOException {
  try (CloseableIterable<InternalRow> rows = Parquet.read(Files.localInput(dataFile))
      .project(SCHEMA)
      .createReaderFunc(type -> SparkParquetReaders.buildReader(SCHEMA, type))
      .build()) {

    Iterable<InternalRow> unsafeRows = Iterables.transform(
        rows,
        APPLY_PROJECTION.bind(SparkBenchmarkUtil.projection(SCHEMA, SCHEMA))::invoke);

    for (InternalRow row : unsafeRows) {
      blackhole.consume(row);
    }
  }
}
 
Example #5
Source Project: adaptive-radix-tree   Author: rohansuri   File: E.java    License: MIT License 6 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public int rangeScanAndInsert(Blackhole bh, EData d) {
    int lastInsert = 0;
    int lastScan = 0;
    for (int i = 0; i < d.operation.length; i++) {
        if (d.operation[i]) { // scan
            NavigableMap<String, Object> tailMap = d.m.tailMap(d.scanStart[lastScan], true);
            // creation of iterator results in one getCeilingEntry call
            Iterator<Map.Entry<String, Object>> tail = tailMap.entrySet().iterator();
            for (int j = 0; j < d.scanRange[lastScan]-1 && tail.hasNext() ; j++) {
                // all next calls, call successors (which calls first on Node)
                bh.consume(tail.next());
            }
            lastScan++;
        } else { // insert
            bh.consume(d.m.put(d.toInsert[lastInsert++], d.holder));
        }
    }
    return d.m.size();
}
 
Example #6
Source Project: doov   Author: doov-io   File: SimpleValidationWithoutShortCircuit.java    License: Apache License 2.0 6 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 1)
@Threads(50)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
public void testSimpleBeanValidation(ValidationState state, Blackhole blackHole) {
    BenchmarkSetup benchmarkSetup = new BenchmarkSetup(BenchmarkModelWrapper::new, state);
    Result result = state.rule.executeOn(benchmarkSetup.model);
    assertThat(getActualViolationCount(result)).isEqualTo(benchmarkSetup.expectedViolationCount);
    blackHole.consume(result);
}
 
Example #7
Source Project: iceberg   Author: apache   File: SparkParquetReadersNestedDataBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
@Benchmark
@Threads(1)
public void readWithProjectionUsingSparkReader(Blackhole blackhole) throws IOException {
  StructType sparkSchema = SparkSchemaUtil.convert(PROJECTED_SCHEMA);
  try (CloseableIterable<InternalRow> rows = Parquet.read(Files.localInput(dataFile))
      .project(PROJECTED_SCHEMA)
      .readSupport(new ParquetReadSupport())
      .set("org.apache.spark.sql.parquet.row.requested_schema", sparkSchema.json())
      .set("spark.sql.parquet.binaryAsString", "false")
      .set("spark.sql.parquet.int96AsTimestamp", "false")
      .callInit()
      .build()) {

    for (InternalRow row : rows) {
      blackhole.consume(row);
    }
  }
}
 
Example #8
Source Project: iceberg   Author: apache   File: SparkParquetReadersFlatDataBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
@Benchmark
@Threads(1)
public void readWithProjectionUsingIcebergReaderUnsafe(Blackhole blackhole) throws IOException {
  try (CloseableIterable<InternalRow> rows = Parquet.read(Files.localInput(dataFile))
      .project(PROJECTED_SCHEMA)
      .createReaderFunc(type -> SparkParquetReaders.buildReader(PROJECTED_SCHEMA, type))
      .build()) {

    Iterable<InternalRow> unsafeRows = Iterables.transform(
        rows,
        APPLY_PROJECTION.bind(SparkBenchmarkUtil.projection(PROJECTED_SCHEMA, PROJECTED_SCHEMA))::invoke);

    for (InternalRow row : unsafeRows) {
      blackhole.consume(row);
    }
  }
}
 
Example #9
Source Project: avro-util   Author: linkedin   File: FastAvroSerdesBenchmark.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(NUMBER_OF_OPERATIONS)
public void testAvroSerialization(Blackhole bh) throws Exception {
  for (int i = 0; i < NUMBER_OF_OPERATIONS; i++) {
    // use vanilla avro 1.4 encoder, do not use buffer binary encoder
    bh.consume(serializer.serialize(generatedRecord));
  }
}
 
Example #10
Source Project: doov   Author: doov-io   File: SimpleValidation.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 1)
@Threads(50)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
public void testSimpleBeanValidation(ValidationState state, Blackhole blackHole) {
    BenchmarkSetup benchmarkSetup = new BenchmarkSetup(BenchmarkModelWrapper::new, state);
    Result result = state.rule.executeOn(benchmarkSetup.model);
    assertThat(result.value()).isEqualTo(benchmarkSetup.expectedResult);
    if (result.value()) {
        assertThat(getActualViolationCount(result)).isEqualTo(0);
    } else {
        assertThat(getActualViolationCount(result)).isEqualTo(1);
    }
    blackHole.consume(result);
}
 
Example #11
Source Project: apm-agent-java   Author: elastic   File: ElasticApmContinuousBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setUp(Blackhole blackhole) throws IOException {
    super.setUp(blackhole);
    final BlackholeConnection blackholeConnection = BlackholeConnection.INSTANCE;
    blackholeConnection.init(blackhole);
    httpServlet = new ElasticApmContinuousBenchmark.BenchmarkingServlet(blackholeConnection, tracer, blackhole);
    System.getProperties().put(Reporter.class.getName(), tracer.getReporter());
}
 
Example #12
Source Project: hadoop-ozone   Author: apache   File: BenchmarkBlockDataToString.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void usingConcatenation(
    BenchmarkBlockDataToString state, Blackhole sink) {
  for (int i = 0; i < state.count; i++) {
    BlockData item = state.data.get(i);
    String str = "[blockId=" +
        item.getBlockID() +
        ",size=" +
        item.getSize() +
        "]";
    sink.consume(str);
    Preconditions.checkArgument(str.equals(state.values.get(i)));
  }
}
 
Example #13
Source Project: Oak   Author: yahoo   File: ScanBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void scan(Blackhole blackhole) {
    Iterator<String> iterator = oakMap.keySet().iterator();

    while (iterator.hasNext()) {
        String val = iterator.next();
        blackhole.consume(val);
    }

}
 
Example #14
Source Project: doov   Author: doov-io   File: BenchmarkOldRule.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void valid_email(Blackhole blackhole) {
    boolean valid = RulesOld.validateEmail(MODEL.getAccount());
    if (blackhole != null) {
        blackhole.consume(valid);
    }
}
 
Example #15
Source Project: raptor   Author: geekshop   File: ClientMockBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void test(Blackhole bh) {
    HelloRequest helloRequest = new HelloRequest();
    helloRequest.setName("ppdai");
    HelloReply helloReply = simple.sayHello(helloRequest);
    bh.consume(helloReply);
}
 
Example #16
Source Project: netty-4.1.22   Author: tianheframe   File: IntObjectHashMapBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Override
void remove(Blackhole bh) {
    Int2ObjectHashMap<Long> copy = new Int2ObjectHashMap<Long>();
    copy.putAll(map);
    for (int key : keys) {
        bh.consume(copy.remove(key));
    }
}
 
Example #17
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 defaultHeaders_serverHandler(Blackhole bh) {
  serverHandler(bh, new DefaultHttp2Headers(true, 9));
}
 
Example #18
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_clientHandler(Blackhole bh) {
  clientHandler(bh, new GrpcHttp2ResponseHeaders(2));
}
 
Example #19
Source Project: teku   Author: PegaSysEng   File: BLSPrimitivesBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void ate1x2Mul(Blackhole bh) {
  FP12 ate1 = PAIR.ate(signature.getSignature().g2Point().getPoint(), g1Generator.getPoint());
  FP12 ate2 = PAIR.ate(signature.getSignature().g2Point().getPoint(), g1Generator.getPoint());
  ate1.mul(ate2);
  bh.consume(ate1);
}
 
Example #20
Source Project: teku   Author: PegaSysEng   File: BitlistBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
public void setAllBits(Blackhole bh) {
  final Bitlist target = createBitlist();
  target.setAllBits(MANY_BITS_SET);
  bh.consume(target);
}
 
Example #21
Source Project: presto   Author: prestosql   File: BenchmarkRoundFunction.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void doubleActual(Blackhole bh)
{
    bh.consume(MathFunctions.round(operand0, numberOfDecimals));
    bh.consume(MathFunctions.round(operand1, numberOfDecimals));
    bh.consume(MathFunctions.round(operand2, numberOfDecimals));
    bh.consume(MathFunctions.round(operand3, numberOfDecimals));
    bh.consume(MathFunctions.round(operand4, numberOfDecimals));
}
 
Example #22
Source Project: presto   Author: prestosql   File: BenchmarkBoxedBoolean.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void primitive(BenchmarkData data, Blackhole blackhole)
{
    for (int i = 0; i < ARRAY_SIZE; i++) {
        if (data.primitives[i]) {
            blackhole.consume(0xDEADBEAF);
        }
        else {
            blackhole.consume(0xBEAFDEAD);
        }
    }
}
 
Example #23
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 httpIterate(Blackhole bh) {
    Iterator<Entry<CharSequence, CharSequence>> itr = httpHeaders.iteratorCharSequence();
    while (itr.hasNext()) {
        bh.consume(itr.next());
    }
}
 
Example #24
Source Project: presto   Author: prestosql   File: BenchmarkBoxedBoolean.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void booleanEquals(BenchmarkData data, Blackhole blackhole)
{
    for (int i = 0; i < ARRAY_SIZE; i++) {
        if (TRUE.equals(data.constants[i])) {
            blackhole.consume(0xDEADBEAF);
        }
        else {
            blackhole.consume(0xBEAFDEAD);
        }
    }
}
 
Example #25
Source Project: teku   Author: PegaSysEng   File: Sha256Benchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@Warmup(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS)
public void sha256of33byteArray(Blackhole bh) {
  int idx = cnt++ % data.size();
  dataArray[idx]++;
  byte[] hash = Hash.sha2_256(dataArray);
  bh.consume(hash);
}
 
Example #26
Source Project: adaptive-radix-tree   Author: rohansuri   File: C.java    License: MIT License 5 votes vote down vote up
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public int lookup(Blackhole bh, CData d) {
    for (int i = 0; i < d.toLookup.length; i++) {
        bh.consume(d.m.get(d.toLookup[i]));
    }
    return d.m.size();
}
 
Example #27
Source Project: doov   Author: doov-io   File: CascadedValidation.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 1)
@Threads(50)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
public void testCascadedValidation(CascadedValidationState state, Blackhole blackhole) {
    DriverSetup driverSetup = new DriverSetup();
    Result result = state.rule.executeOn(driverSetup.model);
    assertThat(result.value()).isTrue();
    blackhole.consume(result);
}
 
Example #28
Source Project: doov   Author: doov-io   File: BenchmarkRuleRewrite.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void test_account_5(Blackhole blackhole) {
    boolean valid = benchRule5.withShortCircuit(false).executeOn(sample).value();
    if (blackhole != null) {
        blackhole.consume(valid);
    }
}
 
Example #29
Source Project: metrics   Author: ultrabrew   File: TagsBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
public void counterDropwizard() {
  final com.codahale.metrics.Counter counter =
      dropwizardRegistry
          .counter(DROPWIZARD_COUNTER_TAGNAME_PREFIX + String.valueOf(tagValue++ % cardinality));
  counter.inc();
  Blackhole.consumeCPU(CONSUME_CPU);
}
 
Example #30
Source Project: jmh-playground   Author: Valloric   File: JMHSample_28_BlackholeHelpers.java    License: Apache License 2.0 5 votes vote down vote up
@Setup
public void setup(final Blackhole bh) {
    workerBaseline = new Worker() {
        double x;

        @Override
        public void work() {
            // do nothing
        }
    };

    workerWrong = new Worker() {
        double x;

        @Override
        public void work() {
            Math.log(x);
        }
    };

    workerRight = new Worker() {
        double x;

        @Override
        public void work() {
            bh.consume(Math.log(x));
        }
    };

}