private void generateImport(PrintWriter writer) { Class<?>[] imports = new Class<?>[]{ List.class, AtomicInteger.class, Collection.class, ArrayList.class, TimeUnit.class, Generated.class, CompilerControl.class, InfraControl.class, ThreadParams.class, Result.class, ThroughputResult.class, AverageTimeResult.class, SampleTimeResult.class, SingleShotResult.class, SampleBuffer.class, Mode.class, Fork.class, Measurement.class, Threads.class, Warmup.class, BenchmarkMode.class, RawResults.class, ResultRole.class, Field.class, BenchmarkParams.class, IterationParams.class }; for (Class<?> c : imports) { writer.println("import " + c.getName() + ';'); } writer.println(); }
@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 ); } }
@Benchmark @Warmup(iterations = 20) public int getAndIncAge(ThreadState state) { Person person = state.person; int oldAge = person.getAge(); person.setAge(oldAge + 1); return oldAge; }
@Benchmark @Warmup(iterations = 20) public void addBoxedAndClear(ThreadState state) { for (int i = 0; i < N; ++i) { state.list.add(i); } state.list.clear(); }
@Benchmark @Warmup(iterations = 20) public void addNullAndClear(ThreadState state) { for (int i = 0; i < N; ++i) { state.list.add(null); } state.list.clear(); }
@Benchmark @Warmup(iterations = 20) public void addNull(ClearedThreadState state) { for (int i = 0; i < N; ++i) { state.list.add(null); } }
@Benchmark @Warmup(iterations = 20) public void addBoxed(ThreadState state) { for (int i = 0; i < N; ++i) { state.list.put(i, i); } }
@Benchmark @Warmup(iterations = 20) public int hash(ThreadState state) { int value = 0; char[] array = state.characters; for (int i = 0; i < array.length; ++i) { value = value * 31 + array[i]; } return value; }
@Benchmark @Warmup(iterations = 5) public void mathLog(ThreadState state) { double[] data = state.data; for (int i = 0; i < data.length; i++) { double[] result = state.result; result[i] = Math.log(data[i]); } }
@Benchmark @Warmup(iterations = 5) public void mathLog10(ThreadState state) { double[] data = state.data; for (int i = 0; i < data.length; i++) { double[] result = state.result; result[i] = Math.log10(data[i]); } }
@Benchmark @Warmup(iterations = 5) public void mathSin(ThreadState state) { double[] data = state.data; for (int i = 0; i < data.length; i++) { double[] result = state.result; result[i] = Math.sin(data[i]); } }
@Benchmark @Warmup(iterations = 5) public void mathCos(ThreadState state) { double[] data = state.data; for (int i = 0; i < data.length; i++) { double[] result = state.result; result[i] = Math.cos(data[i]); } }
@Benchmark @Warmup(iterations = 5) public void mathTan(ThreadState state) { double[] data = state.data; for (int i = 0; i < data.length; i++) { double[] result = state.result; result[i] = Math.tan(data[i]); } }
@Benchmark @Warmup(iterations = 20) public int getNodeClass(StringEquals s) { int sum = 0; for (Node n : s.nodes) { sum += n.getNodeClass().iterableId(); } return sum; }
@Benchmark @Warmup(iterations = 20) public int valueEquals_STRING_EQUALS(StringEquals s) { int result = 0; for (NodePair np : s.valueEqualsNodePairs) { if (np.n1.valueEquals(np.n2)) { result += 27; } else { result += 31; } } return result; }
@Benchmark @Warmup(iterations = 20) public int valueEquals_HASHMAP_COMPUTE_IF_ABSENT(HashMapComputeIfAbsent s) { int result = 0; for (NodePair np : s.valueEqualsNodePairs) { if (np.n1.valueEquals(np.n2)) { result += 27; } else { result += 31; } } return result; }
@Benchmark @Warmup(iterations = 20) public int valueNumberLeaf_HASHMAP_COMPUTE_IF_ABSENT(HashMapComputeIfAbsent s) { int result = 0; for (Node n : s.valueNumberableLeafNodes) { result += (n.getNodeClass().isLeafNode() ? 1 : 0); } return result; }
@Benchmark @Warmup(iterations = 20) public int valueNumberLeaf_STRING_EQUALS(StringEquals s) { int result = 0; for (Node n : s.valueNumberableLeafNodes) { result += (n.getNodeClass().isLeafNode() ? 1 : 0); } return result; }
@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(); } }