You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/09/04 10:19:01 UTC
[GitHub] lexburner commented on issue #2433: [Dubbo-random enhance] replace
Random with ThreadLocalRandom
lexburner commented on issue #2433: [Dubbo-random enhance] replace Random with ThreadLocalRandom
URL: https://github.com/apache/incubator-dubbo/pull/2433#issuecomment-418315744
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();
ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
@Benchmark
public int random() {
return random.nextInt();
}
@Benchmark
public int threadLocalRandom() {
return threadLocalRandom.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
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org