Created
September 8, 2016 12:40
-
-
Save jackmott/d73139c56a0be297150ef959af75b469 to your computer and use it in GitHub Desktop.
jmhtest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sample; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.State; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.infra.Blackhole; | |
import java.util.concurrent.TimeUnit; | |
import java.util.Arrays; | |
import java.util.Random; | |
@State(Scope.Benchmark) | |
public class MyBenchmark { | |
double[] values; | |
@Setup | |
public void setup() | |
{ | |
Random r = new Random(); | |
values = new double[1000000]; | |
for (int i =0; i < values.length;i++) { | |
values[i] = r.nextDouble(); | |
} | |
} | |
/* | |
@Benchmark | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.MILLISECONDS) | |
public double scalar() { | |
return Arrays.stream(values).reduce(0,(acc,x) -> Math.sin(x)); | |
} */ | |
@Benchmark | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.MILLISECONDS) | |
public double parallel() { | |
return Arrays.stream(values).parallel().reduce(0,(acc,x) -> x*x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment