@Test public void testByteBuddyWithProxiesClassCreation() throws Exception { ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddyWithProxy(); assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS))); assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)); assertThat(classByExtensionBenchmark.benchmarkByteBuddyWithProxy().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass()))); assertReturnValues(instance); }
@Benchmark public ExampleClass benchmarkByteBuddyWithProxy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(MethodDelegation.to(ByteBuddyProxyInterceptor.class)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkByteBuddyWithProxy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(MethodDelegation.to(ByteBuddyProxyInterceptor.class)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); } }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkByteBuddyWithProxy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(MethodDelegation.to(ByteBuddyProxyInterceptor.class)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }  }
ClassByExtensionBenchmark { @Benchmark public ExampleClass benchmarkByteBuddyWithProxy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(MethodDelegation.to(ByteBuddyProxyInterceptor.class)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }  @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 benchmarkByteBuddyWithProxy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(MethodDelegation.to(ByteBuddyProxyInterceptor.class)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }  @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; }