Last active
November 23, 2016 11:54
-
-
Save burythehammer/f1c079876dd6a71af6575c2aee0b920d to your computer and use it in GitHub Desktop.
Benchmarking functional interface in Java 8
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 interface Benchmark { | |
static long invoke(Benchmark f) { | |
final long before = System.nanoTime(); | |
f.run(); | |
final long after = System.nanoTime(); | |
return after - before; | |
} | |
void run(); | |
} | |
-// EXAMPLE USAGE | |
-// final List<Integer> list = Lists.newArrayList(4, 5, 6); | |
-// final long timeToExecute = Benchmark.invoke(() -> Collections.shuffle(list)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment