2016-09-28 12:54:00 -06:00
|
|
|
// validating/jmh/JMH1.java
|
2021-01-31 15:42:31 -07:00
|
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
2016-08-10 15:59:47 -06:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2016-08-29 07:27:53 -06:00
|
|
|
package validating.jmh;
|
2016-08-10 15:59:47 -06:00
|
|
|
import java.util.*;
|
|
|
|
import org.openjdk.jmh.annotations.*;
|
2016-09-28 12:54:00 -06:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2016-08-10 15:59:47 -06:00
|
|
|
|
|
|
|
@State(Scope.Thread)
|
2016-09-28 12:54:00 -06:00
|
|
|
@BenchmarkMode(Mode.AverageTime)
|
|
|
|
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
|
|
|
// Increase these three for more accuracy:
|
|
|
|
@Warmup(iterations = 5)
|
|
|
|
@Measurement(iterations = 5)
|
|
|
|
@Fork(1)
|
|
|
|
public class JMH1 {
|
2016-08-10 15:59:47 -06:00
|
|
|
private long[] la;
|
|
|
|
@Setup
|
|
|
|
public void setup() {
|
2016-09-28 12:54:00 -06:00
|
|
|
la = new long[250_000_000];
|
2016-08-10 15:59:47 -06:00
|
|
|
}
|
|
|
|
@Benchmark
|
|
|
|
public void setAll() {
|
|
|
|
Arrays.setAll(la, n -> n);
|
|
|
|
}
|
|
|
|
@Benchmark
|
|
|
|
public void parallelSetAll() {
|
|
|
|
Arrays.parallelSetAll(la, n -> n);
|
|
|
|
}
|
|
|
|
}
|