@@ -0,0 +1,2711 @@
+package de.jpaw.benchmarks.misc;%0A%0Aimport java.util.Random;%0Aimport java.util.UUID;%0Aimport java.util.concurrent.ThreadLocalRandom;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.BenchmarkMode;%0Aimport org.openjdk.jmh.annotations.Mode;%0Aimport org.openjdk.jmh.annotations.OutputTimeUnit;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.Setup;%0Aimport org.openjdk.jmh.annotations.State;%0Aimport org.openjdk.jmh.annotations.Threads;%0Aimport org.openjdk.jmh.infra.Blackhole;%0A%0A// measure the cost of random number / UUID creation, single threaded as well as multi threaded.%0A%0A// java -jar target/jpaw-benchmarks.jar -i 5 -f 5 -wf 3 -wi 3 %22.*BenchRandom.*%22%0A//%0A// results with JDK 11:%0A//Benchmark                       Mode  Cnt     Score   Error  Units%0A//BenchRandom.random              avgt    2    18.772          ns/op%0A//BenchRandom.random8             avgt    2    28.946          ns/op%0A//BenchRandom.randomThreadLocal   avgt    2     3.851          ns/op%0A//BenchRandom.randomThreadLocal8  avgt    2     9.851          ns/op%0A//BenchRandom.randomUUID          avgt    2   375.304          ns/op%0A//BenchRandom.randomUUID8         avgt    2  6721.986          ns/op%0A%0A//results with JDK 17:%0A//Benchmark                       Mode  Cnt     Score   Error  Units%0A//BenchRandom.random              avgt    2    18.694          ns/op%0A//BenchRandom.random8             avgt    2    29.519          ns/op%0A//BenchRandom.randomThreadLocal   avgt    2     4.164          ns/op%0A//BenchRandom.randomThreadLocal8  avgt    2    10.595          ns/op%0A//BenchRandom.randomUUID          avgt    2   372.302          ns/op%0A//BenchRandom.randomUUID8         avgt    2  5571.595          ns/op%0A%0A%0A@State(value = Scope.Thread)%0A@OutputTimeUnit(TimeUnit.NANOSECONDS)%0A@BenchmarkMode(Mode.AverageTime)%0Apublic class BenchRandom %7B%0A    public Random r;%0A%0A    @Setup%0A    public void init() %7B%0A    %09r = new Random(System.nanoTime());%0A    %7D%0A%0A%0A    @Benchmark%0A    public void random(Blackhole bh) %7B%0A        bh.consume(r.nextLong());%0A    %7D%0A%0A    @Threads(8)%0A    @Benchmark%0A    public void random8(Blackhole bh) %7B%0A        bh.consume(r.nextLong());%0A    %7D%0A%0A    @Benchmark%0A    public void randomThreadLocal(Blackhole bh) %7B%0A        bh.consume(ThreadLocalRandom.current().nextLong());%0A    %7D%0A%0A    @Threads(8)%0A    @Benchmark%0A    public void randomThreadLocal8(Blackhole bh) %7B%0A        bh.consume(ThreadLocalRandom.current().nextLong());%0A    %7D%0A%0A    @Benchmark%0A    public void randomUUID(Blackhole bh) %7B%0A        bh.consume(UUID.randomUUID());%0A    %7D%0A%0A    @Threads(8)%0A    @Benchmark%0A    public void randomUUID8(Blackhole bh) %7B%0A        bh.consume(UUID.randomUUID());%0A    %7D%0A%7D%0A

add benchmark on random generators