Skip to content

Instantly share code, notes, and snippets.

@jackmott
Created September 8, 2016 12:31
Show Gist options
  • Select an option

  • Save jackmott/a571a8799e90759ae568920fd9a95037 to your computer and use it in GitHub Desktop.

Select an option

Save jackmott/a571a8799e90759ae568920fd9a95037 to your computer and use it in GitHub Desktop.
morejavatest
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