Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Last active August 29, 2015 14:13
Show Gist options
  • Save ashkrit/a4b5ae2657e6b02df471 to your computer and use it in GitHub Desktop.
Save ashkrit/a4b5ae2657e6b02df471 to your computer and use it in GitHub Desktop.
public static void main(String...args) {
System.out.println("Array " + sumValues( () -> arrayStream()) + " sec");
System.out.println("ArrayList " + sumValues(() -> arrayListStream()) + " sec");
System.out.println("set " + sumValues(() -> setStream()) + " sec");
System.out.println("linkedlist " + sumValues(() -> linkedListStream()) + " sec");
}
public static long sumValues(Supplier<Stream<Integer>> numberSupplier) {
int result = 0;
long fastest = Integer.MAX_VALUE;
for(int cnt=0;cnt<10;cnt++) {
long start = System.nanoTime();
result=numberSupplier.get().parallel().reduce(Integer::sum).get();
long total = System.nanoTime() - start;
fastest = Math.min(fastest, total / 1_000_000);
}
return fastest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment