This commit is contained in:
redkale
2024-10-13 21:27:46 +08:00
parent 85ac8f743d
commit 4e2ba22fc3
3 changed files with 83 additions and 23 deletions

13
pom.xml
View File

@@ -16,6 +16,7 @@
<maven.compiler.target>11</maven.compiler.target>
<junit.version>5.9.0</junit.version>
<jmh.version>1.37</jmh.version>
<maven-jar-plugin.version>3.4.0</maven-jar-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
@@ -41,6 +42,18 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>

View File

@@ -49,7 +49,7 @@ public class CachedInstanceTest {
classLoader = RedkaleClassLoader.currentClassLoader();
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
remoteSource.init(null);
resourceFactory = ResourceFactory.create();
resourceFactory.register(new Environment());
manager = CachedManagerService.create(remoteSource);
@@ -65,7 +65,6 @@ public class CachedInstanceTest {
@Test
public void run1() throws Exception {
RedkaleClassLoader classLoader = RedkaleClassLoader.currentClassLoader();
Class<CachedInstance> instanceClass = CachedInstance.class;
CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, instanceClass);
CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, instanceClass);
@@ -103,7 +102,6 @@ public class CachedInstanceTest {
@Test
public void run2() throws Exception {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
Class<CachedInstance> serviceClass = CachedInstance.class;
CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass);
CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass);
@@ -112,28 +110,10 @@ public class CachedInstanceTest {
SncpClient client = new SncpClient(
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
CachedInstance instance = Sncp.createLocalService(
new RedkaleClassLoader(parent),
"",
serviceClass,
boost,
resourceFactory,
grous,
client,
null,
null,
null);
classLoader, "c", serviceClass, boost, resourceFactory, grous, client, null, null, null);
resourceFactory.inject(instance);
CachedInstance instance2 = Sncp.createLocalService(
new RedkaleClassLoader(parent),
"",
serviceClass,
boost2,
resourceFactory2,
grous,
client,
null,
null,
null);
classLoader, "d", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
resourceFactory2.inject(instance2);
int threads = Runtime.getRuntime().availableProcessors() * 10;

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2016-2116 Redkale
* All rights reserved.
*/
package org.redkale.test.convert;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.redkale.convert.json.JsonConvert;
import org.redkale.convert.pb.ProtobufConvert;
/**
*
* @author zhangjx
*/
@State(Scope.Thread)
public class BenchmarkConvertTest {
private SimpleEntity entry;
@Setup
public void setup() {
entry = SimpleEntity.create();
}
@TearDown
public void tearDown() {
entry = null;
}
@Benchmark
public void testA_Json() {
JsonConvert.root().convertTo(SimpleEntity.class, entry);
}
@Benchmark
public void testB_Protobuf() {
ProtobufConvert.root().convertTo(SimpleEntity.class, entry);
}
// @Test
// public void testBenchmark() throws Exception {
// Options options = new OptionsBuilder()
// .include(BenchmarkConvertTest.class.getSimpleName())
// .forks(1)
// .threads(1)
// .warmupIterations(1)
// .measurementIterations(1)
// .mode(Mode.Throughput)
// .build();
// new Runner(options).run();
// }
public static void main(String[] args) throws Exception {
Options options = new OptionsBuilder()
.include(BenchmarkConvertTest.class.getSimpleName())
.forks(1)
.threads(1)
.warmupIterations(1)
.measurementIterations(1)
.mode(Mode.Throughput)
.build();
new Runner(options).run();
}
}