int main() { int num_iterations = 300000000; Profiler p; Interface ob1_interface = new Object1(0); p = new Profiler("Object1 through interface"); for(int i = 0; i <= num_iterations; i++) { ob1_interface.add(i); } p = null; Object1 ob1_directly = new Object1(0); p = new Profiler("Object1 directly "); for(int i = 0; i <= num_iterations; i++) { ob1_directly.add(i); } p = null; Interface ob2_interface = new Object2(0); p = new Profiler("Object2 through interface"); for(int i = 0; i <= num_iterations; i++) { ob2_interface.add(i); } p = null; Object2 ob2_directly = new Object2(0); p = new Profiler("Object2 directly "); for(int i = 0; i <= num_iterations; i++) { ob2_directly.add(i); } p = null; stdout.printf("----------------------------------------\n"); return 0; } public interface Interface : Object { public abstract void add(int i); } public abstract class AbsObject : Interface, Object { public abstract void add(int i); } public class Object1 : Interface, Object { private int val; public Object1(int i) { this.val = i; } public void add(int i) { this.val += i; } } public class Object2 : AbsObject { private int val; public Object2(int i) { this.val = i; } public override void add(int i) { this.val += i; } } public class Profiler { private string description; private Timer t; public Profiler(string description) { this.description = description; t = new Timer(); t.start(); } ~Profiler() { t.stop(); stdout.printf("%s : %lf\n", description, t.elapsed()); } }