private static void echoTimings() throws Exception {
Method myMethod = MockGBean.class.getMethod("echo", new Class[]{String.class});
FastClass myFastClass = FastClass.create(MockGBean.class);
int myMethodIndex = myFastClass.getIndex("echo", new Class[]{String.class});
String msg = "Some message";
Object[] args = new Object[]{msg};
String result;
MockGBean instance = new MockGBean("foo", 12);
// normal invoke
int iterations = 100000000;
for (int i = 0; i < iterations; i++) {
result = instance.echo(msg);
}
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
result = instance.echo(msg);
}
long end = System.currentTimeMillis();
printResults("Normal", end, start, iterations);
// reflection
iterations = 10000000;
for (int i = 0; i < iterations; i++) {
result = (String) myMethod.invoke(instance, args);
}
start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
result = (String) myMethod.invoke(instance, args);
}
end = System.currentTimeMillis();
printResults("Reflection", end, start, iterations);
// fast class
iterations = 10000000;
for (int i = 0; i < iterations; i++) {
result = (String) myFastClass.invoke(myMethodIndex, instance, args);
}
start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
result = (String) myFastClass.invoke(myMethodIndex, instance, args);
}
end = System.currentTimeMillis();
printResults("FastClass", end, start, iterations);
// start a kernel