@Benchmark @BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime, Mode.SingleShotTime}) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MICROSECONDS) @Measurement(iterations = ITERATIONS_COUNT, time = 1000, timeUnit = TimeUnit.MICROSECONDS) @Fork(1) public Message timeMergeAndBuild() { dummy = ++dummy % Integer.MAX_VALUE; Builder builder = newBuilder(expectedMessage) .getFieldBuilder(galaxyStar, 0) .setField(starName, String.valueOf(dummy)) .mergeFrom(mergeStar1Message) .getFieldBuilder(starPlanet, 0) .mergeFrom(mergePlanet1Message) .toParent() .toParent(); return builder.build(); }
@Benchmark @BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime, Mode.SingleShotTime}) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Warmup(iterations = 5, time = 100, timeUnit = TimeUnit.MICROSECONDS) @Measurement(iterations = ITERATIONS_COUNT, time = 1000, timeUnit = TimeUnit.MICROSECONDS) @Fork(1) public Galaxy timeMergeAndBuildOriginalGM() { dummy = ++dummy % Integer.MAX_VALUE; Galaxy.Builder builder = Galaxy.newBuilder((Galaxy) expectedMessage); builder.getStarBuilder(0) .setName(String.valueOf(dummy)) .mergeFrom(mergeStar1Message) .getPlanetBuilder(0) .mergeFrom(mergePlanet1Message); return builder.build(); }
@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; }
@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; }
@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; }
@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() ); } }
@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 ); } }
@Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark public void sortNewWay() { for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { SortingLongTestJMH.sort(this.array, 0, this.array.length - 1, null, 0, 0); } }
@Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark public void sortOldWay() { for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { Arrays.sort(this.array); } }
@Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark public void sortNewWay() { for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { SortingIntTestJMH.sort(this.array, 0, this.array.length - 1, null, 0, 0); } }
@Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark public void sortCurrentWay() { for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { Arrays.sort(this.array); } }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark() throws Exception { DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) { writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]); } DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); cohort.canCommit().get(); cohort.preCommit().get(); cohort.commit().get(); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception { for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) { DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]); DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); cohort.canCommit().get(); cohort.preCommit().get(); cohort.commit().get(); } }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception { DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) { writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]); } DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); cohort.canCommit().get(); cohort.preCommit().get(); cohort.commit().get(); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception { for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) { DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]); DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); cohort.canCommit().get(); cohort.preCommit().get(); cohort.commit().get(); } }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception { DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) { writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]); } DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); cohort.canCommit().get(); cohort.preCommit().get(); cohort.commit().get(); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception { for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) { DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]); DOMStoreThreePhaseCommitCohort cohort = writeTx.ready(); cohort.canCommit().get(); cohort.preCommit().get(); cohort.commit().get(); } }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark() throws Exception { DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) { writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]); } writeTx.submit().get(); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception { for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) { DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]); writeTx.submit().get(); } }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception { DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) { writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]); } writeTx.submit().get(); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception { for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) { DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]); writeTx.submit().get(); } }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception { DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) { writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]); } writeTx.submit().get(); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception { for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) { DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]); writeTx.submit().get(); } }
@Measurement(iterations = 100, time = 1, timeUnit = TimeUnit.SECONDS) @Benchmark public void testMethod(MyState s) throws Exception { String testInput = getTestValue(s); try { s.valueSink += safeUpper(testInput).hashCode(); } catch (Exception e) { // Ignore. } }
@Benchmark @Warmup(iterations = 1) @BenchmarkMode(Mode.AverageTime) @Measurement(iterations = 3) public void avg() throws InterruptedException { Thread.sleep(50); }
@Benchmark @Warmup(iterations = 1) @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS) @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) public void throughput() throws InterruptedException { Thread.sleep(50); }
@Benchmark @Measurement(iterations = 5, time = 1) @Fork(3) public void filterWithoutSleuth(BenchmarkContext context) throws IOException, ServletException { MockHttpServletRequest request = builder().buildRequest(new MockServletContext()); MockHttpServletResponse response = new MockHttpServletResponse(); response.setContentType(MediaType.APPLICATION_JSON_VALUE); context.dummyFilter.doFilter(request, response, new MockFilterChain()); }
@Benchmark @Measurement(iterations = 5, time = 1) @Fork(3) public void filterWithSleuth(BenchmarkContext context) throws ServletException, IOException { MockHttpServletRequest request = builder().buildRequest(new MockServletContext()); MockHttpServletResponse response = new MockHttpServletResponse(); response.setContentType(MediaType.APPLICATION_JSON_VALUE); context.traceFilter.doFilter(request, response, new MockFilterChain()); }
@Benchmark @Fork(value = FORK_COUNT) @Threads(value = THREAD_COUNT) @Warmup(iterations = WARMUP_COUNT) @Measurement(iterations = ITERATION_COUNT) public String directSupplier() { return stringSupplier.get(); }
@Benchmark @Fork(value = FORK_COUNT) @Threads(value = THREAD_COUNT) @Warmup(iterations = WARMUP_COUNT) @Measurement(iterations = ITERATION_COUNT) public String protectedSupplier() { return protectedSupplier.get(); }
@Benchmark @Fork(value = FORK_COUNT) @Threads(value = THREAD_COUNT) @Warmup(iterations = WARMUP_COUNT) @Measurement(iterations = ITERATION_COUNT) public String protectedSupplierWithSubscriber() { return protectedSupplierWithSb.get(); }
@Benchmark @Threads(value = THREAD_COUNT) @Warmup(iterations = WARMUP_COUNT) @Fork(value = FORK_COUNT) @Measurement(iterations = ITERATION_COUNT) public String semaphoreBasedPermission() { return semaphoreGuardedSupplier.get(); }
@Benchmark @Threads(value = THREAD_COUNT) @Warmup(iterations = WARMUP_COUNT) @Fork(value = FORK_COUNT) @Measurement(iterations = ITERATION_COUNT) public String atomicPermission() { return atomicGuardedSupplier.get(); }