@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) { } }
@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) { } }
@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(); }
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 @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 ); } }
/** * This benchmark attempts to measure the performance without any context propagation. * * @param blackhole a {@link Blackhole} object supplied by JMH */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Fork public void none(Blackhole blackhole) throws InterruptedException { Thread t = new Thread(new MyRunnable(blackhole)); t.start(); t.join(); }
/** * This benchmark attempts to measure the performance with manual context propagation. * * @param blackhole a {@link Blackhole} object supplied by JMH */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Fork public void manual(Blackhole blackhole) throws InterruptedException { Thread t = new Thread((Context.current().wrap(new MyRunnable(blackhole)))); t.start(); t.join(); }
/** * This benchmark attempts to measure the performance with automatic context propagation. * * @param blackhole a {@link Blackhole} object supplied by JMH */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Fork(jvmArgsAppend = "-javaagent:contrib/agent/build/libs/agent.jar") public void automatic(Blackhole blackhole) throws InterruptedException { Thread t = new Thread(new MyRunnable(blackhole)); t.start(); t.join(); }
/** * This benchmark attempts to measure the performance without any context propagation. * * @param blackhole a {@link Blackhole} object supplied by JMH */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Fork public void none(final Blackhole blackhole) { MoreExecutors.directExecutor().execute(new MyRunnable(blackhole)); }
/** * This benchmark attempts to measure the performance with manual context propagation. * * @param blackhole a {@link Blackhole} object supplied by JMH */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Fork public void manual(final Blackhole blackhole) { MoreExecutors.directExecutor().execute(Context.current().wrap(new MyRunnable(blackhole))); }
/** * This benchmark attempts to measure the performance with automatic context propagation. * * @param blackhole a {@link Blackhole} object supplied by JMH */ @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Fork(jvmArgsAppend = "-javaagent:contrib/agent/build/libs/agent.jar") public void automatic(final Blackhole blackhole) { MoreExecutors.directExecutor().execute(new MyRunnable(blackhole)); }
@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 /*Result "benchmarkCurrentImplementation": 696.179 ±(99.9%) 10.576 ns/op [Average] (min, avg, max) = (638.682, 696.179, 1119.323), stdev = 44.779 CI (99.9%): [685.603, 706.754] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkCurrentImplementation() { return SimpleCounter.getBarcodeConsensus(barcodes, 4); }
@Benchmark /*Result "benchmarkOriginalImplementation": 1754.640 ±(99.9%) 14.679 ns/op [Average] (min, avg, max) = (1627.906, 1754.640, 1849.707), stdev = 62.154 CI (99.9%): [1739.961, 1769.320] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkOriginalImplementation() { return getBarcodeConsensusOriginal(barcodes.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation1": 1225.031 ±(99.9%) 23.223 ns/op [Average] (min, avg, max) = (1156.470, 1225.031, 2437.182), stdev = 98.326 CI (99.9%): [1201.808, 1248.253] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkImplementation1() { return getBarcodeConsensus1(barcodes.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation2": 1219.853 ±(99.9%) 20.397 ns/op [Average] (min, avg, max) = (1109.666, 1219.853, 2047.413), stdev = 86.364 CI (99.9%): [1199.456, 1240.251] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkImplementation2() { return getBarcodeConsensus2(barcodes.stream(), 4); }
@Benchmark /*Result "benchmarkCurrentImplementationLongList": 2140.760 ±(99.9%) 3.571 ns/op [Average] (min, avg, max) = (2103.459, 2140.760, 2207.486), stdev = 15.118 CI (99.9%): [2137.190, 2144.331] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkCurrentImplementationLongList() { return SimpleCounter.getBarcodeConsensus(longerBarcodeList, 4); }
@Benchmark /*Result "benchmarkOriginalImplementationLongList": 17673.306 ±(99.9%) 71.294 ns/op [Average] (min, avg, max) = (15895.117, 17673.306, 18165.695), stdev = 301.864 CI (99.9%): [17602.012, 17744.600] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkOriginalImplementationLongList() { return getBarcodeConsensusOriginal(longerBarcodeList.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation1LongList": 2079.771 ±(99.9%) 4.368 ns/op [Average] (min, avg, max) = (2037.663, 2079.771, 2139.046), stdev = 18.493 CI (99.9%): [2075.403, 2084.138] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkImplementation1LongList() { return getBarcodeConsensus1(longerBarcodeList.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation2LongList": 2062.632 ±(99.9%) 4.671 ns/op [Average] (min, avg, max) = (2005.671, 2062.632, 2110.788), stdev = 19.775 CI (99.9%): [2057.962, 2067.303] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, G1}) public byte[] benchmarkImplementation2LongList() { return getBarcodeConsensus2(longerBarcodeList.stream(), 4); }
/** * Same benchmarks as above, with parallel GC */ @Benchmark /*Result "benchmarkCurrentImplementationPGC": 667.441 ±(99.9%) 9.137 ns/op [Average] (min, avg, max) = (594.590, 667.441, 773.722), stdev = 38.687 CI (99.9%): [658.304, 676.578] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkCurrentImplementationPGC() { return SimpleCounter.getBarcodeConsensus(barcodes, 4); }
@Benchmark /*Result "benchmarkOriginalImplementationPGC": 1811.790 ±(99.9%) 12.351 ns/op [Average] (min, avg, max) = (1647.858, 1811.790, 1888.886), stdev = 52.295 CI (99.9%): [1799.438, 1824.141] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkOriginalImplementationPGC() { return getBarcodeConsensusOriginal(barcodes.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation1PGC": 758.192 ±(99.9%) 5.420 ns/op [Average] (min, avg, max) = (694.177, 758.192, 831.377), stdev = 22.949 CI (99.9%): [752.772, 763.612] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkImplementation1PGC() { return getBarcodeConsensus1(barcodes.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation2PGC": 754.002 ±(99.9%) 9.131 ns/op [Average] (min, avg, max) = (689.518, 754.002, 1205.087), stdev = 38.661 CI (99.9%): [744.871, 763.133] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkImplementation2PGC() { return getBarcodeConsensus2(barcodes.stream(), 4); }
@Benchmark /*Result "benchmarkCurrentImplementationLongListPGC": 2192.949 ±(99.9%) 3.427 ns/op [Average] (min, avg, max) = (2151.208, 2192.949, 2225.582), stdev = 14.511 CI (99.9%): [2189.522, 2196.377] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkCurrentImplementationLongListPGC() { return SimpleCounter.getBarcodeConsensus(longerBarcodeList, 4); }
@Benchmark /*Result "benchmarkOriginalImplementationLongListPGC": 17775.573 ±(99.9%) 77.276 ns/op [Average] (min, avg, max) = (16921.565, 17775.573, 18582.101), stdev = 327.190 CI (99.9%): [17698.298, 17852.849] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkOriginalImplementationLongListPGC() { return getBarcodeConsensusOriginal(longerBarcodeList.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation1LongListPGC": 2209.661 ±(99.9%) 4.818 ns/op [Average] (min, avg, max) = (2167.050, 2209.661, 2264.874), stdev = 20.399 CI (99.9%): [2204.843, 2214.479] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkImplementation1LongListPGC() { return getBarcodeConsensus1(longerBarcodeList.stream(), 4); }
@Benchmark /*Result "benchmarkImplementation2LongListPGC": 2106.950 ±(99.9%) 6.097 ns/op [Average] (min, avg, max) = (2020.543, 2106.950, 2168.021), stdev = 25.817 CI (99.9%): [2100.852, 2113.047] (assumes normal distribution) */ @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}) public byte[] benchmarkImplementation2LongListPGC() { return getBarcodeConsensus2(longerBarcodeList.stream(), 4); }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, G1}) /* Result "benchmarkJDKImplementation": 404.973 ±(99.9%) 1.134 ns/op [Average] (min, avg, max) = (396.532, 404.973, 423.267), stdev = 4.802 CI (99.9%): [403.839, 406.107] (assumes normal distribution) */ public Quality benchmarkJDKImplementation() { return getMin(mapJDK); }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, G1}) /* Result "benchmarkCustomImplementation": 163.892 ±(99.9%) 1.257 ns/op [Average] (min, avg, max) = (158.934, 163.892, 181.983), stdev = 5.324 CI (99.9%): [162.635, 165.149] (assumes normal distribution) */ public Quality benchmarkCustomImplementation() { return getMin(mapCustom); }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 5) public int benchmarkOldImplementation(Data d) { SettableInteger sum = new SettableInteger(0); d.map.forEachValueOld(v -> { sum.addAndGet(v); return true; }); return sum.get(); }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 5) public int benchmarkNewImplementation(Data d) { SettableInteger sum = new SettableInteger(0); d.map.forEachValue(v -> { sum.addAndGet(v); return true; }); return sum.get(); }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 20) public int benchmarkMonomorphic(Data d) { int result = 0; result += d.mapMono.put(12345, 12345); result += d.customMapPoly.put(12345, 12345); return result; }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 20) public int benchmarkPolymorphic(Data d) { int result = 0; result += d.mapPoly.put(12345, 12345); result += d.customMapPoly.put(12345, 12345); return result; }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 20) public int benchmarkPolymorphicOnly1ImplementationCalledA(Data d) { int result = 0; result += d.mapPoly.put(12345, 12345); result += d.mapPoly.put(12346, 12346); return result; }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 20) public int benchmarkPolymorphicOnly1ImplementationCalledB(Data d) { int result = 0; result += d.customMapPoly.put(12345, 12345); result += d.customMapPoly.put(12346, 12346); return result; }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 5) public int benchmarkValueIterator(Data d) { int sum = 0; for (Integer i: d.map.values()) { sum += i; } return sum; }
@Benchmark @Fork(jvmArgsAppend = {MAX_MEM, PARALLEL_GC_1, PARALLEL_GC_2}, value = 5) public int benchmarkForEachSI(Data d) { SettableInteger sum = new SettableInteger(0); d.map.forEachValue(v -> { sum.addAndGet(v); return true; }); return sum.get(); }