Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created July 7, 2013 12:19
Show Gist options
  • Save ashkrit/5943293 to your computer and use it in GitHub Desktop.
Save ashkrit/5943293 to your computer and use it in GitHub Desktop.
private double x = Math.PI;
@GenerateMicroBenchmark
public void baseline() {
// do nothing, this is a baseline
}
@GenerateMicroBenchmark
public double measureWrong() {
// This is wrong: the result is provably the same, optimized out.
return Math.log(Math.PI);
}
@GenerateMicroBenchmark
public double measureRight() {
// This is correct: the result is being used.
return Math.log(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment