org.openjdk.jmh.infra.Blackhole Java Examples

The following examples show how to use org.openjdk.jmh.infra.Blackhole. 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: SparkParquetReadersFlatDataBenchmark.java    From iceberg with 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 #2
Source File: SparkParquetReadersNestedDataBenchmark.java    From iceberg with 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 #3
Source File: BenchMarkOzoneManager.java    From hadoop-ozone with 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 #4
Source File: SparkParquetReadersFlatDataBenchmark.java    From iceberg with 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 File: SimpleValidationWithoutShortCircuit.java    From doov with 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 #6
Source File: BenchmarkBlockDataToString.java    From hadoop-ozone with 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 #7
Source File: OkhttpRaptorServerBenchmark.java    From raptor with 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 #8
Source File: E.java    From adaptive-radix-tree with 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 #9
Source File: TagsBenchmark.java    From metrics with 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 #10
Source File: FastAvroSerdesBenchmark.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(NUMBER_OF_OPERATIONS)
public void testFastAvroSerialization(Blackhole bh) throws Exception {
  for (int i = 0; i < NUMBER_OF_OPERATIONS; i++) {
    bh.consume(fastSerializer.serialize(generatedRecord));
  }
}
 
Example #11
Source File: BenchmarkRuleRewrite.java    From doov with 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 #12
Source File: CascadedValidation.java    From doov with 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 #13
Source File: C.java    From adaptive-radix-tree with 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 #14
Source File: Sha256Benchmark.java    From teku with 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 #15
Source File: BenchmarkBoxedBoolean.java    From presto with 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 #16
Source File: HeadersBenchmark.java    From netty-4.1.22 with 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 #17
Source File: BenchmarkBoxedBoolean.java    From presto with 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 #18
Source File: ElasticApmContinuousBenchmark.java    From apm-agent-java with 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 #19
Source File: JMHSample_28_BlackholeHelpers.java    From jmh-playground with 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));
        }
    };

}
 
Example #20
Source File: HeadersBenchmark.java    From netty-4.1.22 with 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 #21
Source File: FastAvroSerdesBenchmark.java    From avro-util with 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 #22
Source File: JMHSample_37_CacheAccess.java    From jmh-playground with Apache License 2.0 5 votes vote down vote up
@Benchmark
@OperationsPerInvocation(MATRIX_SIZE)
public void colFirst(Blackhole bh) {
    for (int c = 0; c < COUNT; c++) {
        for (int r = 0; r < COUNT; r++) {
            bh.consume(matrix[r][c]);
        }
    }
}
 
Example #23
Source File: EmitBenchmark.java    From metrics with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void testEmitArray(final Blackhole bh, BenchmarkState state) {
  emit(bh, "measurement1", new String[]{
          ENDPOINT, "/api/v1/ping",
          CLIENT, "domain.testservice",
          STATUS, String.valueOf(state.foo++)},
      1L);
}
 
Example #24
Source File: EmitBenchmark.java    From metrics with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void testEmitVarargs(final Blackhole bh, BenchmarkState state) {
  emit(bh, "measurement1", 1L,
      ENDPOINT, "/api/v1/ping",
      CLIENT, "domain.testservice",
      STATUS, String.valueOf(state.foo++));
}
 
Example #25
Source File: BenchmarkRuleRewrite.java    From doov with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void test_account_4_short_circuit(Blackhole blackhole) {
    boolean valid = benchRule4.executeOn(sample).value();
    if (blackhole != null) {
        blackhole.consume(valid);
    }
}
 
Example #26
Source File: IteratorPerf.java    From jmh-playground with Apache License 2.0 5 votes vote down vote up
@Benchmark
public int forEachLoopInts(Blackhole blackhole) {
  perturbIntList();
  int sum = 0;
  for (int i : ints) {
    sum += i;
  }
  return sum;
}
 
Example #27
Source File: TagArrayBenchmark.java    From metrics with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void testTagArray(final Blackhole bh) {
  tagArray.put(key1, thing1);
  tagArray.put(key2, thing2);
  tagArray.put(key3, thing3);
  useArray(bh, tagArray.toArray());
}
 
Example #28
Source File: BenchmarkRule.java    From doov with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void valid_country(Blackhole blackhole) {
    boolean valid = COUNTRY.executeOn(MODEL).value();
    if (blackhole != null) {
        blackhole.consume(valid);
    }
}
 
Example #29
Source File: PutBenchmark.java    From Oak with Apache License 2.0 5 votes vote down vote up
@Warmup(iterations = 5)
@Measurement(iterations = 10)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 1)
@Threads(8)
@Benchmark
public void put(Blackhole blackhole,BenchmarkState state,ThreadState threadState) {
    for (int i = 0; i < threadState.numRows; ++i) {
        Map.Entry<String, String> pair = threadState.rows.get(i);
        state.oakMap.zc().put(pair.getKey(), pair.getValue());
        blackhole.consume(state.oakMap);
    }
}
 
Example #30
Source File: BenchmarkRuleRewrite.java    From doov with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void test_account_short_circuit(Blackhole blackhole) {
    boolean valid = benchRule1.executeOn(sample).value();
    if (blackhole != null) {
        blackhole.consume(valid);
    }
}