Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Created March 29, 2009 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipertracker/87518 to your computer and use it in GitHub Desktop.
Save hipertracker/87518 to your computer and use it in GitHub Desktop.
public class Bench {
static int i;
static class A {
void perform() {
i++;
}
}
static class B extends A{
void perform() {
i += 4;
}
}
public static void main(String[]args) {
for(int iter=0; iter<10; iter++) bench();
System.out.println(i);
}
static void bench() {
long t = System.currentTimeMillis();
A a = new A();
A b = new B();
for (int i=0;i<400000000;i++) {
A x = (i & 1) == 0 ? a : b;
x.perform();
}
System.out.println(System.currentTimeMillis() - t);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment