@Benchmark public void benchmarkGuava(AppState appState, ContextState ctxState) { TypedMap data; if (appState.numDataEntries == 0) { data = TypedMap.empty(); } else { final GuavaTypedMap.Builder builder = GuavaTypedMap.Builder .with(appState.dataKeys.get(0), ctxState.datas.get(0)); IntStream.range(1, appState.numDataEntries).forEach( i -> { builder.add(appState.dataKeys.get(i), ctxState.datas.get(i)); } ); data = builder.build(); } IntStream.range(0, ctxState.numRecordings).forEach( i -> { appState.sink.useData(data); } ); }
@Benchmark public byte[] byCharsetEncoder_US_ASCII() { try { CharsetEncoder encoder = asciiencode.get(); CharBuffer buffer = charbuffergenerator.get(); buffer.clear(); buffer.append(STR); buffer.flip(); ByteBuffer outbuffer = bytebuffergenerator.get(); outbuffer.clear(); CoderResult result = encoder.encode(buffer, outbuffer, false); if (result.isError()) { result.throwException(); } byte[] b = new byte[STR.length()]; outbuffer.flip(); outbuffer.get(b); return b; } catch (CharacterCodingException e) { throw new RuntimeException(e); } }
@Benchmark public void measureAcquireAndReleaseSingleThreaded() throws Exception { try (Resource<Thing> thingResource = pool.get()) { Thing thing = thingResource.get(); assertNotNull(thing); assertEquals(1, thing.getId()); } }
@Benchmark @CompilerControl(CompilerControl.Mode.DONT_INLINE) public double[] BranchyCopyAndMask(ArrayWithNegatives state) { double[] data = state.data; double[] result = state.target; System.arraycopy(data, 0, result, 0, data.length); for (int i = 0; i < result.length; ++i) { if (result[i] < 0D) { result[i] = 0D; } } return result; }
@Benchmark public String mapConstN() throws InterruptedException, ExecutionException { CompletableFuture<String> f = constFuture; for (int i = 0; i < N.n; i++) f = f.thenApplyAsync(mapF); return f.get(); }
@Benchmark @CompilerControl(CompilerControl.Mode.DONT_INLINE) public double[] NewArray(ArrayWithNegatives state) { double[] data = state.data; double[] result = state.target; for (int i = 0; i < result.length; ++i) { result[i] = Math.max(data[i], 0D); } return result; }
@Benchmark public Optional<byte[]> aes_GCM_Decrypt() throws Exception { try { final Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); final GCMParameterSpec gcmSpec = new GCMParameterSpec(128, nonce); final SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmSpec); return Optional.of(cipher.doFinal(gcmCiphertext)); } catch (BadPaddingException e) { return Optional.empty(); } }
@Benchmark public byte[] aes_GCM_Encrypt() throws Exception { final Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); final GCMParameterSpec gcmSpec = new GCMParameterSpec(128, nonce); final SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec); return cipher.doFinal(plaintext); }
@Benchmark @Group("pingpong") public void pong(Control cnt) { while (!cnt.stopMeasurement && !flag.compareAndSet(true, false)) { // this body is intentionally left blank } }
@Benchmark public void creationTime(Blackhole bh) { Map seriesMap = ((MetricsAndTagStoreImpl) ((ChunkImpl) chunkStore).getStore()).getMetricStore() .getSeriesMap(); OffHeapVarBitMetricStore newStore = OffHeapVarBitMetricStore.toOffHeapStore(seriesMap, "", ""); bh.consume(newStore); }
@Benchmark public List<Person> filterECLazy_serial() { List<Person> filtered = Person.getECPeople() .asLazy() .select(person -> person.getHeightInInches() < 150) .select(person -> person.getHeightInInches() > 80) .toList(); return filtered; }
@Benchmark public Void ensurePromise() throws Exception { Promise<Void> p = new Promise<Void>(); Future<Void> f = p.ensure(ensureF); p.setValue(null); return Await.result(f); }
@Benchmark public String flatMapConstN() throws InterruptedException, ExecutionException { CompletableFuture<String> f = constFuture; for (int i = 0; i < N.n; i++) f = f.thenCompose(flatMapF); return f.get(); }
@Benchmark @OperationsPerInvocation(TESTSIZE) public Object[] cloneObjectArray() { int j = 0; for (int i = 0; i < TESTSIZE; i++) { dummy[j++] = arraysClone(testObjectArray[i]); } return dummy; }
@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 public void nanoTimeElapsed(Blackhole bh) { long nanoTimeEnd = System.nanoTime(); long elapsed = nanoTimeEnd - nanoTimeStart; bh.consume(elapsed); nanoTimeStart = nanoTimeEnd; }
@CompilerControl(CompilerControl.Mode.DONT_INLINE) @Benchmark public int NaiveSum(IntData state) { int value = 0; int[] data = state.data1; for (int i = 0; i < data.length; ++i) { value += data[i]; } return value; }
@CompilerControl(CompilerControl.Mode.DONT_INLINE) @Benchmark public int Scale_Int(IntData state) { int value = 0; int[] data = state.data1; for (int i = 0; i < data.length; ++i) { value += 10 * data[i]; } return value; }
@Benchmark public IntSummaryStatistics uniqueAgesSummaryStatisticsJDK_serial() { final Set<Integer> uniqueAges = Person.getJDKPeople().stream() .mapToInt(Person::getAge) .boxed() .collect(Collectors.toSet()); IntSummaryStatistics summary = uniqueAges.stream().mapToInt(i -> i).summaryStatistics(); return summary; }
@Benchmark public SummaryStatistics<Person> combinedStatisticsECSinglePassStream_serial() { SummaryStatistics<Person> summaryStatistics = new SummaryStatistics<Person>() .addDoubleFunction("height", Person::getHeightInInches) .addDoubleFunction("weight", Person::getWeightInPounds) .addIntFunction("age", Person::getAge); return Person.getECPeople().stream().collect(summaryStatistics.toCollector()); }
@Benchmark @OperationsPerInvocation(COMPARISONS_PER_INVOCATION) public final void compareFourBytes(final Blackhole blackhole) { int res = 0; for (int i = 0; i < COMPARISONS_PER_INVOCATION; ++i) { res += FasterByteComparison.compare(FOUR_BYTES, MANY_BYTES); } blackhole.consume(res); }
@Benchmark public String mapPromiseN() throws Exception { Promise<String> p = new Promise<String>(); Future<String> f = p; for (int i = 0; i < N.n; i++) f = f.map(mapF); p.setValue(string); return Await.result(f); }
@Benchmark public Void ensurePromiseN() throws Exception { Promise<Void> p = new Promise<>(); Future<Void> f = p; for (int i = 0; i < N.n; i++) f = f.ensure(ensureF); p.setValue(null); return Await.result(f); }
@Benchmark @CompilerControl(CompilerControl.Mode.DONT_INLINE) //makes looking at assembly easier public int[] hashLoop(Context context) { for (int i = 0; i < SIZE; i++) { context.results[i] = getHashPosition(context.values[i], 1048575); } return context.results; }
@Benchmark public Void ensurePromiseN() throws Exception { Promise<Void> p = Promise.<Void>apply(); Future<Void> f = p.future(); for (int i = 0; i < N.n; i++) f = f.transform(ensureF, ec); p.success(null); return Await.result(f, inf); }
@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 public int pairwiseOr_RoaringWithRun(BenchmarkState benchmarkState) { int total = 0; for(int k = 0; k + 1 < benchmarkState.rc.size(); ++k) total += RoaringBitmap.or(benchmarkState.rc.get(k),benchmarkState.rc.get(k+1)).getCardinality(); if(total != benchmarkState.totalor ) throw new RuntimeException("bad pairwise or result"); return total; }
@Benchmark public int pairwiseAnd_RoaringWithRun(BenchmarkState benchmarkState) { int total = 0; for(int k = 0; k + 1 < benchmarkState.rc.size(); ++k) total += RoaringBitmap.and(benchmarkState.rc.get(k),benchmarkState.rc.get(k+1)).getCardinality(); if(total != benchmarkState.totaland ) throw new RuntimeException("bad pairwise and result"); return total; }
@Benchmark public int pairwiseAnd_EWAH32(BenchmarkState benchmarkState) { int total = 0; for(int k = 0; k + 1 < benchmarkState.ewah32.size(); ++k) total += benchmarkState.ewah32.get(k).and(benchmarkState.ewah32.get(k+1)).cardinality(); if(total !=benchmarkState.totaland ) throw new RuntimeException("bad pairwise and result"); return total; }
@Benchmark public Void ensureConstN() throws Exception { Future<Void> f = constVoidFuture; for (int i = 0; i < N.n; i++) f = f.ensure(ensureF); return Await.result(f); }
@Benchmark public Void ensureConstN() throws Exception { Future<Void> f = constVoidFuture; for (int i = 0; i < N.n; i++) f.transform(ensureF, ec); return Await.result(f, inf); }
@Benchmark @CompilerControl(CompilerControl.Mode.DONT_INLINE) //makes looking at assembly easier public void increment(Context context) { for (int i = 0; i < SIZE; i++) { context.temporary[i] = context.values[i] + 1; } }
@Benchmark @Group("pingpong") public void ping(Control cnt) { while (!cnt.stopMeasurement && !flag.compareAndSet(false, true)) { // this body is intentionally left blank } }
@Benchmark public String mapPromise() throws InterruptedException, ExecutionException { CompletableFuture<String> p = new CompletableFuture<String>(); CompletableFuture<String> f = p.thenApplyAsync(mapF); p.complete(string); return f.get(); }
@Benchmark @OperationsPerInvocation(COMPARISONS_PER_INVOCATION) public final void compareThirtyTwoBytes(final Blackhole blackhole) { int res = 0; for (int i = 0; i < COMPARISONS_PER_INVOCATION; ++i) { res += FasterByteComparison.compare(THIRTY_TWO_BYTES, MANY_BYTES); } blackhole.consume(res); }
@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 public void roundTripSmallTimes1000LowAllocation(Blackhole b) { for (long i = 0; i < N; i++) { small.point(i, point); b.consume(i == small.index(point)); } }
@Benchmark public String flatMapConstN() throws CheckedFutureException { Future<String> f = constFuture; for (int i = 0; i < N.n; i++) f = f.flatMap(flatMapF); return f.get(Duration.ofMillis(Long.MAX_VALUE)); }
@Benchmark public String flatMapConstN() throws Exception { Future<String> f = constFuture; for (int i = 0; i < N.n; i++) f = f.flatMap(flatMapF, ec); return Await.result(f, inf); }
@OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @Benchmark public int testFieldAccessReflectionApi(FieldAccessReflectionApiState state) throws IllegalArgumentException, IllegalAccessException { return state.intValField.getInt(state.foo); }