Skip to content

Instantly share code, notes, and snippets.

@guipn
Created May 7, 2011 20:39
Show Gist options
  • Save guipn/960819 to your computer and use it in GitHub Desktop.
Save guipn/960819 to your computer and use it in GitHub Desktop.
Simple Java Benchmarking
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