Skip to content

Instantly share code, notes, and snippets.

@burythehammer
Last active November 23, 2016 11:54
Show Gist options
  • Save burythehammer/f1c079876dd6a71af6575c2aee0b920d to your computer and use it in GitHub Desktop.
Save burythehammer/f1c079876dd6a71af6575c2aee0b920d to your computer and use it in GitHub Desktop.
Benchmarking functional interface in Java 8
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