Created
May 7, 2011 20:39
-
-
Save guipn/960819 to your computer and use it in GitHub Desktop.
Simple Java Benchmarking
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
class SimpleBenchmark | |
{ | |
private Runnable task; | |
public Benchmark(Runnable target) | |
{ | |
task = target; | |
} | |
public long perform() | |
{ | |
long start = System.nanoTime(); | |
task.run(); | |
return System.nanoTime() - start; | |
} | |
} | |
/* | |
Example: | |
public static void main(String args[]) | |
{ | |
Runnable test = | |
new Runnable() | |
{ | |
public void run() | |
{ | |
int i; | |
for (i = 0; i < 10; i++) {} | |
} | |
}; | |
Benchmark bmark = new Benchmark(test); | |
System.out.println("This takes " + bmark.perform() + " nanoseconds."); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment