Over a million developers have joined DZone.

Microbenchmark For Bridge Vs Reflection Vs Direct Access

·
import java.lang.reflect.Method;

public class TimingTest {
	public interface IFoo { public void foo(); }
	public interface PubFoo { public void foo(); }
	public static class Impl implements PubFoo { public void foo(){} }

	static final int COUNT = 10000000;
	public static void main(String[] args) throws Exception {
		Impl impl = new Impl();
		int count;

		startTiming("Bridge (including BCEL)");
		IFoo ifoo = Bridge.expose(impl, IFoo.class);
		stopTiming();
		startTiming("Bridge (BCEL loaded)");
		Bridge.expose(impl, PubFoo.class);
		stopTiming();

		System.out.println(COUNT+" virtual invocations, warm");

		startTiming("Direct");
		for(int i=0; i
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}