Created
September 8, 2016 12:31
-
-
Save jackmott/a571a8799e90759ae568920fd9a95037 to your computer and use it in GitHub Desktop.
morejavatest
This file contains hidden or 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
| import java.util.concurrent.TimeUnit; | |
| import java.util.Arrays; | |
| import java.util.Random; | |
| import java.lang.*; | |
| public class Speed { | |
| public static void main(String[] args) { | |
| double[] values = new double[1000000]; | |
| Random r = new Random(); | |
| double result; | |
| long start; | |
| long end; | |
| while (true) | |
| { | |
| for (int i = 0; i < values.length;i++) | |
| { | |
| values[i] = r.nextDouble(); | |
| } | |
| //check for dead entities | |
| start = System.nanoTime(); | |
| result = Arrays.stream(values).parallel().reduce(0,(acc,x) -> x*x); | |
| end = System.nanoTime(); | |
| double time = (end-start) / 1000000.0; | |
| System.out.println("Time:" + time + " Result:"+result);; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment