@Test public void testByteBuddyClassCreation() throws Exception { ExampleInterface instance = classByImplementationBenchmark.benchmarkByteBuddy(); assertThat(Arrays.asList(instance.getClass().getInterfaces()), hasItem(ClassByImplementationBenchmark.BASE_CLASS)); assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(Object.class)); assertThat(classByImplementationBenchmark.benchmarkByteBuddy().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass()))); assertReturnValues(instance); }
@Benchmark public ExampleInterface benchmarkByteBuddy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(StubMethod.INSTANCE) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
ClassByImplementationBenchmark { @Benchmark public ExampleInterface benchmarkByteBuddy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(StubMethod.INSTANCE) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); } }
ClassByImplementationBenchmark { @Benchmark public ExampleInterface benchmarkByteBuddy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(StubMethod.INSTANCE) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }  }
ClassByImplementationBenchmark { @Benchmark public ExampleInterface benchmarkByteBuddy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(StubMethod.INSTANCE) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }  @Setup void setup(); @Benchmark ExampleInterface baseline(); @Benchmark ExampleInterface benchmarkByteBuddy(); @Benchmark ExampleInterface benchmarkByteBuddyWithTypePool(); @Benchmark ExampleInterface benchmarkCglib(); @Benchmark ExampleInterface benchmarkJavassist(); @Benchmark ExampleInterface benchmarkJdkProxy(); }
ClassByImplementationBenchmark { @Benchmark public ExampleInterface benchmarkByteBuddy() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(StubMethod.INSTANCE) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }  @Setup void setup(); @Benchmark ExampleInterface baseline(); @Benchmark ExampleInterface benchmarkByteBuddy(); @Benchmark ExampleInterface benchmarkByteBuddyWithTypePool(); @Benchmark ExampleInterface benchmarkCglib(); @Benchmark ExampleInterface benchmarkJavassist(); @Benchmark ExampleInterface benchmarkJdkProxy(); static final Class<? extends ExampleInterface> BASE_CLASS; static final String DEFAULT_REFERENCE_VALUE; static final boolean DEFAULT_BOOLEAN_VALUE; static final byte DEFAULT_BYTE_VALUE; static final short DEFAULT_SHORT_VALUE; static final char DEFAULT_CHAR_VALUE; static final int DEFAULT_INT_VALUE; static final long DEFAULT_LONG_VALUE; static final float DEFAULT_FLOAT_VALUE; static final double DEFAULT_DOUBLE_VALUE; }