Java 类org.openjdk.jmh.annotations.Mode 实例源码

项目:qpp-conversion-tool    文件:ParameterizedBenchmarkTest.java   
@BeforeAll
static void loadPaths() throws IOException, RunnerException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    String[] paths;
    fileSystem = FileTestHelper.createMockFileSystem(Configuration.unix());
    fileSystemField = ConversionEntry.class.getDeclaredField("fileSystem");
    fileSystemField.setAccessible(true);
    defaultFileSystem = (FileSystem) fileSystemField.get(null);
    fileSystemField.set(null, fileSystem);
    paths = FileTestHelper.getAllQrdaFiles(fileSystem, "-latest.xml").map(Path::toString).toArray(String[]::new);

    Options opt = new OptionsBuilder()
            .mode(Mode.Throughput)
            .mode(Mode.AverageTime)
            .include(".*" + ParameterizedBenchmark.class.getSimpleName() + ".*")
            .param("fileName", paths)
            .forks(1)
            .build();

    List<RunResult> results = new ArrayList<>(new Runner(opt).run());
    benchResults = results.stream()
            .map(RunResult::getAggregatedResult)
            .collect(Collectors.toList());
}
项目:alog    文件:AlogBenchmark.java   
@Test
public void run() throws Exception {
    //Add more iterations, forks, etc, results should be similar or better.  At least they
    //were on my machine.
    Options opt = new OptionsBuilder()
            .include(this.getClass().getName() + ".*")
            //.mode(Mode.Throughput)
            .mode(Mode.AverageTime)
            .timeUnit(TimeUnit.MICROSECONDS)
            .warmupIterations(5)
            .measurementIterations(5)
            .forks(1)
            .threads(10)
            .shouldDoGC(true)
            .jvmArgs("")
            .build();
    new Runner(opt).run();
}
项目:mumu-rocketmq    文件:RocketMQAsyncMessage.java   
/**
 * 发送异步消息
 * @throws InterruptedException
 * @throws RemotingException
 * @throws MQClientException
 * @throws MQBrokerException
 */
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void sendAsyncMessage() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    producer.send(new Message(RocketMQConfiguration.ROCKETMQ_TOPIC,message), new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            //System.out.println("receive message"+sendResult);
        }

        @Override
        public void onException(Throwable throwable) {
            //System.out.println("receive message error"+throwable.getLocalizedMessage());
        }
    });
}
项目:atomic    文件:Driver.java   
public static void main(String[] args) throws RunnerException {
    for (int threads = 1; threads < 32; threads <<= 1) {
        Options opt = new OptionsBuilder()
                .forks(10)
                .threads(threads)
                .warmupIterations(10)
                .measurementIterations(20)
                .mode(Mode.AverageTime)
                .timeUnit(TimeUnit.NANOSECONDS)
                .include("ky.korins.atomic.benchmark")
                .resultFormat(ResultFormatType.CSV)
                .result("atomic_" + threads + ".csv")
                .build();

        new Runner(opt).run();
    }
}
项目:direwolves    文件:ValidationBenchmarks.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(1)
@OperationsPerInvocation(10000)
public void testApi() {
  Map<String, Object> data = new HashMap<String, Object>();
  data.put("encryptKey", "0000000000000000");
  data.put("barcode", "LH10312ACCF23C4F3A5");

  Multimap<String, Rule> rules = ArrayListMultimap.create();

  rules.put("barcode", Rule.required());
  rules.put("barcode", Rule.regex("[0-9A-F]{16}"));
  rules.put("encryptKey", Rule.required());
  rules.put("encryptKey", Rule.regex("LH[0-7][0-9a-fA-F]{2}[0-5][0-4][0-9a-fA-F]{12}"));
  try {
    Validations.validate(data, rules);
  } catch (Exception e) {
  }

}
项目:direwolves    文件:ValidationBenchmarks.java   
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(1)
@OperationsPerInvocation(10000)
public void testAverage() {
  Map<String, Object> data = new HashMap<String, Object>();
  data.put("encryptKey", "0000000000000000");
  data.put("barcode", "LH10312ACCF23C4F3A5");

  Multimap<String, Rule> rules = ArrayListMultimap.create();

  rules.put("barcode", Rule.required());
  rules.put("barcode", Rule.regex("[0-9A-F]{16}"));
  rules.put("encryptKey", Rule.required());
  rules.put("encryptKey", Rule.regex("LH[0-7][0-9a-fA-F]{2}[0-5][0-4][0-9a-fA-F]{12}"));
  try {
    Validations.validate(data, rules);
  } catch (Exception e) {
  }
}
项目:deltaforce    文件:ClientOrderBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void latency() throws InvalidObjectException {
    ClientOrderBuilder order = new ClientOrderBuilder();
    order.setClientId(1234);
    order.setAssignee("ALGO");
    order.setBoardCode("MAIN");
    order.setCurrencyCode("HKD");
    order.setQuantity(1000);
    order.setId(123456789);
    order.setPrice(3.0);
    order.setCreatedBy("CREATEDBY");
    order.setUpdatedBy("UPDATEDBY");
    order.setExchangeCode("1234");
    order.setFixOrder(true);
    order.setCreatedTime(System.currentTimeMillis());
    order.setOrderStatus((byte) 'a');
    order.setSide((byte) '1');

    order.apply();
    orders[(index++) % orders.length] = order;
}
项目:javapgperf    文件:Main.java   
public static void main(String[] args) throws RunnerException {
    if(args.length != 1 || args[0] == null || args[0].isEmpty()) {
        System.exit(1);
    }
    String testName = args[0];

    Options opt = addTestToOptionsBuilder(new OptionsBuilder(), testName)
            .forks(NO_FORKS_RUN_ON_THE_SAME_JVM)
            // We need to avoid warmup iterations as they however counts towards total Postgres time
            .warmupIterations(0)
            .measurementIterations(ITERATIONS)
            .timeUnit(TimeUnit.MILLISECONDS)
            .mode(Mode.SingleShotTime)
            .verbosity(VerboseMode.SILENT)
            .build();

    Collection<RunResult> runResults = new Runner(opt).run();

    runResults.stream().forEach(runResult ->
        System.out.printf(
                "Java:\t%s\t%.2f\n",
                runResult.getParams().getBenchmark(),
                runResult.getPrimaryResult().getScore()
        )
    );
}
项目:gradle-jmh-report    文件:PullPushBenchmark.java   
@Benchmark
@CompilerControl(org.openjdk.jmh.annotations.CompilerControl.Mode.EXCLUDE)
public long pushWithoutJit() {
    Reader reader = new Reader(MAX, _nulls);
    PushConsumer consumer = new PushConsumer();
    for (int i = 0; i < reader.getMax(); i++) {
        boolean nextIsNull = reader.nextIsNull();
        if (nextIsNull) {
            consumer.consumeNull();
        } else {
            consumer.consume(reader.readNext());
        }
    }
    assertThat(consumer.getSum()).isEqualTo(4950000000000000L);
    assertThat(consumer.getNullCount()).isEqualTo(1000000);
    return consumer.getSum();
}
项目:benchmarks    文件:ReentrantLockBenchmark.java   
@Benchmark
@BenchmarkMode({   Mode.Throughput})
  @OutputTimeUnit
    (TimeUnit.MILLISECONDS)
public long testUnfairLockContended(Contended contended )
{
    contended.unfairLock.lock();
    try{
        return execute();
    }
    finally
    {
        contended.unfairLock.unlock();
    }



}
项目:benchmarks    文件:ReentrantLockBenchmark.java   
@Benchmark
@BenchmarkMode({   Mode.Throughput})
  @OutputTimeUnit
    (TimeUnit.MILLISECONDS)
public long testFairLockContended(Contended contended)
{
    contended.fairLock.lock();
    try{
        return execute();
    }
    finally
    {
        contended.fairLock.unlock();
    }



}
项目:incubator-pirk    文件:PaillierBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void testWithGMP(PaillierBenchmarkState allState)
{
  SystemConfiguration.setProperty("paillier.useGMPForModPow", "true");
  SystemConfiguration.setProperty("paillier.GMPConstantTimeMode", "false");
  ModPowAbstraction.reloadConfiguration();

  try
  {
    allState.pallier.encrypt(allState.m1, allState.r1);
  } catch (PIRException e)
  {
    logger.info("Exception in testWithGMP!\n");
  }
}
项目:incubator-pirk    文件:PaillierBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void testWithGMPConstantTime(PaillierBenchmarkState allState)
{
  SystemConfiguration.setProperty("paillier.useGMPForModPow", "true");
  SystemConfiguration.setProperty("paillier.GMPConstantTimeMode", "true");
  ModPowAbstraction.reloadConfiguration();

  try
  {
    allState.pallier.encrypt(allState.m1, allState.r1);
  } catch (PIRException e)
  {
    logger.info("Exception in testWithGMPConstantTime!\n");
  }
}
项目:requery    文件:BenchmarkTest.java   
@Test
public void testCompareQuery() throws SQLException, RunnerException {
    Options options = new OptionsBuilder()
        .include(getClass().getName() + ".*")
        .mode(Mode.SingleShotTime)
        .timeUnit(TimeUnit.MILLISECONDS)
        .warmupTime(TimeValue.seconds(5))
        .warmupIterations(2)
        .measurementTime(TimeValue.seconds(10))
        .measurementIterations(5)
        .threads(1)
        .forks(2)
        .build();
    try {
        new Runner(options).run();
    } catch (NoBenchmarksException ignored) {
        // expected? only happens from gradle
    }
}
项目:CalculationEngine    文件:BenchmarkTestParent.java   
@Test
public void startAllBenchmarks() throws Exception {
    ChainedOptionsBuilder opts = new OptionsBuilder()
                                        .mode(Mode.SampleTime)
                                        .timeUnit(TimeUnit.NANOSECONDS)
                                        .warmupTime(TimeValue.seconds(1))
                                        .warmupIterations(8)
                                        .measurementTime(TimeValue.seconds(1))
                                        .measurementIterations(5)
                                        .timeout(TimeValue.seconds(30))
                                        .threads(2)
                                        .forks(1) //0 for debug, 1 for run
                                        .shouldFailOnError(true)
                                        .shouldDoGC(true) //because of graph
                                        .addProfiler(profilers.FlightRecordingProfiler.class);

    new Runner(opts.include(getClass().getSimpleName() + ".*").build()).run();
}
项目:decimal4j    文件:JmhRunner.java   
public static void main(String[] args) throws RunnerException, IOException {
    final String include;
    if (args.length == 0) {
        include = askRunAll();
    } else {
        include = args[0];
    }
    final Options opt = new OptionsBuilder()//
        .include(include)//
        .mode(Mode.Throughput)//
        .measurementIterations(3)//
        .measurementBatchSize(1)//
        .measurementTime(TimeValue.milliseconds(1000))//
        .forks(1)//
        .timeUnit(TimeUnit.MICROSECONDS)//
        .warmupIterations(3)//
        .warmupTime(TimeValue.milliseconds(1000))//
        .build();
    final Collection<RunResult> runResult = new Runner(opt).run();
    System.out.flush();
    final ResultFormat resultFormat = ResultFormatFactory.getInstance(ResultFormatType.CSV, System.out);
    resultFormat.writeOut(runResult);
    System.out.flush();
}
项目:tchannel-java    文件:PingPongMultiServerBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void benchmark(final AdditionalCounters counters) throws Exception {
    JsonRequest<Ping> request = new JsonRequest.Builder<Ping>("ping-server", "ping")
        .setBody(new Ping("ping?"))
        .setTimeout(20000)
        .setRetryLimit(0)
        .build();

    TFuture<JsonResponse<Pong>> future = this.subClient.send(request);
    future.addCallback(new TFutureCallback<JsonResponse<Pong>>() {
        @Override
        public void onResponse(JsonResponse<Pong> pongResponse) {
            if (!pongResponse.isError()) {
                counters.actualQPS.incrementAndGet();
            } else {
                counters.errorQPS.incrementAndGet();
            }
        }
    });
}
项目:jmh    文件:CompilerControlInlineActualTest.java   
@Test
public void testGMB() throws RunnerException {
    for (Mode mode : Mode.values()) {
        if (mode == Mode.All) continue;

        Options opts = new OptionsBuilder()
                .include(Fixtures.getTestMask(this.getClass()))
                .mode(mode)
                .shouldFailOnError(true)
                .addProfiler(LogConsumeProfiler.class)
                .measurementIterations(mode == Mode.SingleShotTime ? 100000 : 1)
                .measurementTime(TimeValue.seconds(5))
                .warmupIterations(0)
                .forks(1)
                .build();
        RunResult runResult = new Runner(opts).runSingle();

        if (CompilerControlUtils.check(runResult, "@", "callee")) { // Poor man's check -XX:+PrintInlining works
            Assert.assertTrue("Failed with " + mode,
                    CompilerControlUtils.check(runResult, this.getClass().getName() + "::compilerControlSpecimen", "force inline by"));
            Assert.assertTrue("Failed with " + mode,
                    CompilerControlUtils.check(runResult, this.getClass().getName() + "::strawMethod", "force inline by"));
        }
    }
}
项目:jmh    文件:CompilerControlDontInlineActualTest.java   
@Test
public void testGMB() throws RunnerException {
    for (Mode mode : Mode.values()) {
        if (mode == Mode.All) continue;

        Options opts = new OptionsBuilder()
                .include(Fixtures.getTestMask(this.getClass()))
                .mode(mode)
                .shouldFailOnError(true)
                .addProfiler(LogConsumeProfiler.class)
                .measurementIterations(mode == Mode.SingleShotTime ? 100000 : 1)
                .measurementTime(TimeValue.seconds(5))
                .warmupIterations(0)
                .forks(1)
                .build();
        RunResult runResult = new Runner(opts).runSingle();

        if (CompilerControlUtils.check(runResult, "@", "callee")) { // Poor man's check -XX:+PrintInlining works
            Assert.assertTrue("Failed with " + mode,
                    CompilerControlUtils.check(runResult, this.getClass().getName() + "::compilerControlSpecimen", "disallowed by"));
            Assert.assertTrue("Failed with " + mode,
                    CompilerControlUtils.check(runResult, this.getClass().getName() + "::strawMethod", "disallowed by"));
        }
    }
}
项目:jmh    文件:BenchmarkGenerator.java   
/**
 * Generate the method for a specific benchmark method
 */
private void generateMethod(ClassInfo classInfo, Mode benchmarkKind, PrintWriter writer, MethodGroup methodGroup, StateObjectHandler states) {
    writer.println();
    switch (benchmarkKind) {
        case Throughput:
            generateThroughput(classInfo, writer, benchmarkKind, methodGroup, states);
            break;
        case AverageTime:
            generateAverageTime(classInfo, writer, benchmarkKind, methodGroup, states);
            break;
        case SampleTime:
            generateSampleTime(classInfo, writer, benchmarkKind, methodGroup, states);
            break;
        case SingleShotTime:
            generateSingleShotTime(classInfo, writer, benchmarkKind, methodGroup, states);
            break;
        default:
            throw new AssertionError("Shouldn't be here");
    }
}
项目:mumu-rocketmq    文件:RocketMQSyncMessage.java   
/**
 * 发送同步消息
 * @throws InterruptedException
 * @throws RemotingException
 * @throws MQClientException
 * @throws MQBrokerException
 */
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void sendMessage(){
    try {
        SendResult sendResult = producer.send(new Message(RocketMQConfiguration.ROCKETMQ_TOPIC, message));
    } catch (Exception e) {
        //e.printStackTrace();
    }
}
项目:mumu-benchmark    文件:JMHSample_26_BatchSize.java   
@Benchmark
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@BenchmarkMode(Mode.AverageTime)
public List<String> measureWrong_1() {
    list.add(list.size() / 2, "something");
    return list;
}
项目:mumu-benchmark    文件:JMHSample_26_BatchSize.java   
@Benchmark
@Warmup(iterations = 5, time = 5)
@Measurement(iterations = 5, time = 5)
@BenchmarkMode(Mode.AverageTime)
public List<String> measureWrong_5() {
    list.add(list.size() / 2, "something");
    return list;
}
项目:mumu-benchmark    文件:JMHSample_26_BatchSize.java   
@Benchmark
@Warmup(iterations = 5, batchSize = 5000)
@Measurement(iterations = 5, batchSize = 5000)
@BenchmarkMode(Mode.SingleShotTime)
public List<String> measureRight() {
    list.add(list.size() / 2, "something");
    return list;
}
项目:mumu-benchmark    文件:JMHSample_32_BulkWarmup.java   
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public int measure(Counter c) {
    int s = 0;
    for (int i = 0; i < 10; i++) {
        s += c.inc();
    }
    return s;
}
项目:beanvalidation-benchmark    文件:ParsingBeansSpeedBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 1)
@Threads(1)
@Warmup(iterations = 5)
@Measurement(iterations = 20)
public void testCascadedValidation(ParsingBeansSpeedState state, Blackhole bh) {
    // Validator in new factory

    for ( Object o : state.holder.beans ) {
        bh.consume( state.validator.getConstraintsForClass( o.getClass() ).isBeanConstrained() );
    }
}
项目:beanvalidation-benchmark    文件:RawValidationSpeedBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@Fork(value = 1)
@Threads(50)
@Warmup(iterations = 20) // it seems that as there are a lot of beans it takes some time to warmup
@Measurement(iterations = 30)
public void testCascadedValidation(RawValidationSpeedState state, Blackhole bh) {
    for ( Object o : state.holder.beans ) {
        Set<ConstraintViolation<Object>> constraintViolations = state.validator.validate( o );
        bh.consume( constraintViolations );
    }
}
项目:gather    文件:TestGatherPerformance.java   
public static void main(String[] args) throws RunnerException {
    Options options = new OptionsBuilder().include(TestGatherPerformance.class.getSimpleName())
                                         .warmupIterations(5)
                                         .measurementIterations(20)
                                         .threads(1)
                                         .forks(1)
                                         .mode(Mode.Throughput)
                                         .build();

    new Runner(options).run();
}
项目:CodeKatas    文件:IntListJMHTest.java   
public static void main(String[] args) throws RunnerException
{
    Options options = new OptionsBuilder().include(".*" + IntListJMHTest.class.getSimpleName() + ".*")
            .forks(2)
            .mode(Mode.Throughput)
            .timeUnit(TimeUnit.SECONDS)
            .build();
    new Runner(options).run();
}
项目:CodeKatas    文件:PersonJMHTest.java   
public static void main(String[] args) throws RunnerException
{
    Options options = new OptionsBuilder().include(".*" + PersonJMHTest.class.getSimpleName() + ".*")
            .forks(2)
            .mode(Mode.Throughput)
            .timeUnit(TimeUnit.SECONDS)
            .build();
    new Runner(options).run();
}
项目:mumu-zbus    文件:ZbusProcedureBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void sendMessage(){
    try {
        Message msg = new Message(new String(MESSAGE_BYTES));
        //msg.setTopic(ZbusConfiguration.topicName);
        Message message = producer.sendSync(msg);
        //producer.sendAsync(msg);
    }catch (Exception e){
        e.printStackTrace();
    }
}
项目:org.ops4j.pax.transx    文件:PreparedStatementBench.java   
@Benchmark
@CompilerControl(CompilerControl.Mode.INLINE)
public Statement cycleStatement(Blackhole bh, ConnectionState state) throws SQLException
{
    PreparedStatement statement = state.connection.prepareStatement("INSERT INTO test (column) VALUES (?)");
    statement.setInt(1, 1);
    bh.consume(statement.executeUpdate());
    statement.close();
    return statement;
}
项目:org.ops4j.pax.transx    文件:StatementBench.java   
@Benchmark
@CompilerControl(CompilerControl.Mode.INLINE)
public Statement cycleStatement(Blackhole bh, ConnectionState state) throws SQLException
{
    Statement statement = state.connection.createStatement();
    bh.consume(statement.execute("INSERT INTO test (column) VALUES (?)"));
    statement.close();
    return statement;
}
项目:org.ops4j.pax.transx    文件:ConnectionBench.java   
@Benchmark
@CompilerControl(CompilerControl.Mode.INLINE)
public static Connection cycleConnection() throws SQLException
{
    Connection connection = DS.getConnection();
    connection.close();
    return connection;
}
项目:faster-than-reflection    文件:FasterThanReflectionBenchmark.java   
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
@Benchmark
public int testFieldAccessReflectionApi(FieldAccessReflectionApiState state)
        throws IllegalArgumentException, IllegalAccessException {
    return state.intValField.getInt(state.foo);
}
项目:faster-than-reflection    文件:FasterThanReflectionBenchmark.java   
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
@Benchmark
public int testPropertyAccessReflectionApi(PropertyAccessReflectionApiState state)
        throws IllegalAccessException, InvocationTargetException {
    return (int)state.intValAccessorMethod.invoke(state.foo);
}
项目:preDict    文件:LuceneBenchmark.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public List<String> testSingleSearch(Data data, Iterator i) {
    String query = null;
    while(query == null) {
        query = i.getNextQuery(data.queries);
    }
    return data.wordSearch.findSimilarWords(query);
}
项目:prometheus-client    文件:SummaryThroughputTest.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void measureSimpleClientSummaryThroughput() {
  promSummary = io.prometheus.client.Summary.build().name("name").help("help").create();
  for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
    promSummary.observe(i);
  }
}
项目:prometheus-client    文件:SummaryThroughputTest.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void measureSimpleClientSummaryThroughputWithLabels() {
  promSummary = io.prometheus.client.Summary.build().name("name").help("help").labelNames(LABEL_NAMES).create();
  for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
    promSummary.labels(LABEL_VALUES.get(i % LABEL_VALUES.size())).observe(i);
  }
}
项目:prometheus-client    文件:SummaryThroughputTest.java   
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void measureSummaryThroughput() {
  summary = new SummaryBuilder("name", "help").build();
  for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
    summary.observe(i);
  }
}