forked from java8/Java8InAction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectorHarness.java
More file actions
23 lines (19 loc) · 861 Bytes
/
CollectorHarness.java
File metadata and controls
23 lines (19 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package lambdasinaction.chap6;
import java.util.function.*;
public class CollectorHarness {
public static void main(String[] args) {
//System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimes) + " msecs");
System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimesWithCustomCollector) + " msecs" );
}
private static long execute(Consumer<Integer> primePartitioner) {
long fastest = Long.MAX_VALUE;
for (int i = 0; i < 10; i++) {
long start = System.nanoTime();
primePartitioner.accept(1_000_000);
long duration = (System.nanoTime() - start) / 1_000_000;
if (duration < fastest) fastest = duration;
System.out.println("done in " + duration);
}
return fastest;
}
}