use JMH to benchmark the performance of these two class

```
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 3, time = 5)
@Measurement(iterations = 3, time = 5)
@Threads(10)
@Fork(1)
@State(Scope.Benchmark)
public class RandomBenchmark {

    Random random = new Random();

    @Benchmark
    public int random() {
        return random.nextInt();
    }

    @Benchmark
    public int threadLocalRandom() {
        return ThreadLocalRandom.current().nextInt();
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(RandomBenchmark.class.getSimpleName())
                .build();

        new Runner(opt).run();
    }

}
```

and the output is shown below

```
Benchmark                          Mode  Cnt    Score     Error  Units
RandomBenchmark.random             avgt    3  648.175 ± 267.727  ns/op
RandomBenchmark.threadLocalRandom  avgt    3   18.935 ±  19.511  ns/op
```

[ Full content available at: 
https://github.com/apache/incubator-dubbo/pull/2433 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to