@Test public void testCglibClassCreation() throws Exception { ExampleClass instance = classByExtensionBenchmark.benchmarkCglib(); assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS))); assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)); assertThat(classByExtensionBenchmark.benchmarkCglib().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass()))); assertReturnValues(instance); }
@Benchmark public ExampleClass benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setUseFactory(false); enhancer.setInterceptDuringConstruction(true); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); CallbackHelper callbackHelper = new CallbackHelper(baseClass, new Class[0]) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new MethodInterceptor() { public Object intercept(Object object, Method method, Object[] arguments, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(object, arguments); } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleClass) enhancer.create(); }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setUseFactory(false); enhancer.setInterceptDuringConstruction(true); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); CallbackHelper callbackHelper = new CallbackHelper(baseClass, new Class[0]) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new MethodInterceptor() { public Object intercept(Object object, Method method, Object[] arguments, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(object, arguments); } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleClass) enhancer.create(); } }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setUseFactory(false); enhancer.setInterceptDuringConstruction(true); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); CallbackHelper callbackHelper = new CallbackHelper(baseClass, new Class[0]) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new MethodInterceptor() { public Object intercept(Object object, Method method, Object[] arguments, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(object, arguments); } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleClass) enhancer.create(); }  }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setUseFactory(false); enhancer.setInterceptDuringConstruction(true); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); CallbackHelper callbackHelper = new CallbackHelper(baseClass, new Class[0]) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new MethodInterceptor() { public Object intercept(Object object, Method method, Object[] arguments, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(object, arguments); } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleClass) enhancer.create(); }  @Setup void setup(); @Benchmark ExampleClass baseline(); @Benchmark ExampleClass benchmarkByteBuddyWithProxy(); @Benchmark ExampleClass benchmarkByteBuddyWithProxyAndReusedDelegator(); @Benchmark ExampleClass benchmarkByteBuddyWithProxyWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithProxyAndReusedDelegatorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessor(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessorAndReusedDelegator(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessorAndReusedDelegatorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefix(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefixAndReusedDelegator(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefixWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefixAndReusedDelegatorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddySpecialized(); @Benchmark ExampleClass benchmarkCglib(); @Benchmark ExampleClass benchmarkJavassist(); }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setUseFactory(false); enhancer.setInterceptDuringConstruction(true); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); CallbackHelper callbackHelper = new CallbackHelper(baseClass, new Class[0]) { protected Object getCallback(Method method) { if (method.getDeclaringClass() == baseClass) { return new MethodInterceptor() { public Object intercept(Object object, Method method, Object[] arguments, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(object, arguments); } }; } else { return NoOp.INSTANCE; } } }; enhancer.setCallbackFilter(callbackHelper); enhancer.setCallbacks(callbackHelper.getCallbacks()); return (ExampleClass) enhancer.create(); }  @Setup void setup(); @Benchmark ExampleClass baseline(); @Benchmark ExampleClass benchmarkByteBuddyWithProxy(); @Benchmark ExampleClass benchmarkByteBuddyWithProxyAndReusedDelegator(); @Benchmark ExampleClass benchmarkByteBuddyWithProxyWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithProxyAndReusedDelegatorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessor(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessorAndReusedDelegator(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithAccessorAndReusedDelegatorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefix(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefixAndReusedDelegator(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefixWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddyWithPrefixAndReusedDelegatorWithTypePool(); @Benchmark ExampleClass benchmarkByteBuddySpecialized(); @Benchmark ExampleClass benchmarkCglib(); @Benchmark ExampleClass benchmarkJavassist(); static final Class<? extends ExampleClass> BASE_CLASS; }