forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add jmh test for javassist vs reflect
- Loading branch information
xuanmie
committed
Oct 14, 2018
1 parent
29ef6c4
commit 0a5eb91
Showing
10 changed files
with
211 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
example/src/test/java/com/alipay/sofa/rpc/quickstart/JmhTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.alipay.sofa.rpc.quickstart; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.alipay.sofa.rpc.config.ConsumerConfig; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
/** | ||
* | ||
* @author stateis0 | ||
* @date 2018/10/14-下午4:26 | ||
*/ | ||
@State(Scope.Thread) | ||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime}) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Fork(0) | ||
public class JmhTest { | ||
|
||
static ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() | ||
.setInterfaceId(HelloService.class.getName()) // 指定接口 | ||
.setProtocol("bolt") // 指定协议 | ||
.setDirectUrl("bolt://127.0.0.1:9696") // 指定直连地址 | ||
.setConnectTimeout(10 * 1000); | ||
|
||
static HelloService helloService = consumerConfig.refer(); | ||
|
||
static ConsumerConfig<HelloService2> consumerConfig2 = new ConsumerConfig<HelloService2>() | ||
.setInterfaceId(HelloService2.class.getName()) // 指定接口 | ||
.setProtocol("bolt") // 指定协议 | ||
.setDirectUrl("bolt://127.0.0.1:9697") // 指定直连地址 | ||
.setConnectTimeout(10 * 1000); | ||
|
||
static HelloService2 helloService2 = consumerConfig2.refer(); | ||
|
||
|
||
|
||
@Benchmark | ||
public void jdk() { | ||
helloService.jdkTest99("jdkTest99"); | ||
} | ||
|
||
@Benchmark | ||
public void javassist() { | ||
helloService2.javassist("javassist"); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder().include(JmhTest.class.getSimpleName()).build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
|
||
} | ||
|
59 changes: 59 additions & 0 deletions
59
example/src/test/java/com/alipay/sofa/rpc/quickstart/NormalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.alipay.sofa.rpc.quickstart; | ||
|
||
import com.alipay.sofa.rpc.config.ConsumerConfig; | ||
|
||
import org.openjdk.jmh.runner.RunnerException; | ||
|
||
/** | ||
* | ||
* | ||
* @author 玄灭 | ||
* @date 2018/10/14-下午6:42 | ||
*/ | ||
public class NormalTest { | ||
|
||
static ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() | ||
.setInterfaceId(HelloService.class.getName()) // 指定接口 | ||
.setProtocol("bolt") // 指定协议 | ||
.setDirectUrl("bolt://127.0.0.1:9696") // 指定直连地址 | ||
.setConnectTimeout(10 * 1000); | ||
|
||
static HelloService helloService = consumerConfig.refer(); | ||
|
||
static ConsumerConfig<HelloService2> consumerConfig2 = new ConsumerConfig<HelloService2>() | ||
.setInterfaceId(HelloService2.class.getName()) // 指定接口 | ||
.setProtocol("bolt") // 指定协议 | ||
.setDirectUrl("bolt://127.0.0.1:9697") // 指定直连地址 | ||
.setConnectTimeout(10 * 1000); | ||
|
||
static HelloService2 helloService2 = consumerConfig2.refer(); | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
|
||
warp(); | ||
|
||
long s = System.currentTimeMillis(); | ||
|
||
for (int i = 0; i < 100000; i++) { | ||
helloService.jdkTest99("jdkTest99");//15321 | ||
} | ||
long e = System.currentTimeMillis(); | ||
System.out.println(e - s); | ||
|
||
|
||
|
||
s = System.currentTimeMillis(); | ||
for (int i = 0; i < 100000; i++) { | ||
helloService.jdkTest99("jdkTest99");//15321 | ||
} | ||
e = System.currentTimeMillis(); | ||
System.out.println(e - s); | ||
} | ||
|
||
private static void warp() { | ||
for (int i = 0; i < 100000; i++) { | ||
helloService.jdkTest99("jdkTest99");//15321 | ||
helloService2.javassist("javassist");//14172 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters