Skip to content

Instantly share code, notes, and snippets.

@Fabszn
Created June 11, 2012 23:03
Show Gist options
  • Save Fabszn/2913268 to your computer and use it in GitHub Desktop.
Save Fabszn/2913268 to your computer and use it in GitHub Desktop.
public class BenchmarkProxyManager implements InvocationHandler {
private Benchmark o;
public BenchmarkProxyManager(Benchmark o) {
this.o = o;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final StopWatch sw = Provider.buildNewStopWatch();
sw.start();
Object o = method.invoke(this.o, args);
sw.stop();
System.out.println(method.getName() + ": " + sw.getTime() + " ms");
sw.reset();
return o;
}
public static Benchmark getProxiedClass(Class<? extends Benchmark> clazz) {
Benchmark benchmark = null;
try {
benchmark = (Benchmark) Proxy.newProxyInstance(
Benchmark.class.getClassLoader(),
new Class[]{Benchmark.class},
new BenchmarkProxyManager(clazz.newInstance()));
} catch (Exception e) {
e.printStackTrace();
}
return benchmark;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment