use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.
the class ClassByExtensionBenchmarkTest method testByteBuddySpecializedClassCreation.
@Test
public void testByteBuddySpecializedClassCreation() throws Exception {
ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddySpecialized();
assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS)));
assertThat(instance.getClass().getSuperclass(), CoreMatchers.<Class<?>>is(ClassByExtensionBenchmark.BASE_CLASS));
assertThat(classByExtensionBenchmark.benchmarkByteBuddySpecialized().getClass(), not(CoreMatchers.<Class<?>>is(instance.getClass())));
assertReturnValues(instance);
}
use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.
the class ClassByExtensionBenchmark method benchmarkJavassist.
/**
* Performs a benchmark of a class extension using javassist proxies.
*
* @return The created instance, in order to avoid JIT removal.
* @throws java.lang.Exception If the invocation causes an exception.
*/
@Benchmark
public ExampleClass benchmarkJavassist() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory() {
@Override
protected ClassLoader getClassLoader() {
return newClassLoader();
}
};
proxyFactory.setUseCache(false);
proxyFactory.setSuperclass(baseClass);
proxyFactory.setFilter(new MethodFilter() {
public boolean isHandled(Method method) {
return method.getDeclaringClass() == baseClass;
}
});
@SuppressWarnings("unchecked") Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
return proceed.invoke(self, args);
}
});
return (ExampleClass) instance;
}
use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.
the class ClassByExtensionBenchmarkTest method testByteBuddyWithProxiesClassCreation.
@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);
}
use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.
the class ClassByExtensionBenchmarkTest method testByteBuddyWithProxiesClassCreationWithTypePool.
@Test
public void testByteBuddyWithProxiesClassCreationWithTypePool() throws Exception {
ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddyWithProxyWithTypePool();
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);
}
use of net.bytebuddy.benchmark.specimen.ExampleClass in project byte-buddy by raphw.
the class ClassByExtensionBenchmarkTest method testByteBuddyWithPrefixClassCreationWithTypePool.
@Test
public void testByteBuddyWithPrefixClassCreationWithTypePool() throws Exception {
ExampleClass instance = classByExtensionBenchmark.benchmarkByteBuddyWithPrefixWithTypePool();
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);
}
Aggregations