Last active
August 29, 2015 14:13
-
-
Save ashkrit/a4b5ae2657e6b02df471 to your computer and use it in GitHub Desktop.
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
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