Skip to content

Instantly share code, notes, and snippets.

@junwen12221
Created January 28, 2017 09:27
Show Gist options
  • Save junwen12221/a2227e2680eff16f1b149cad53d301a7 to your computer and use it in GitHub Desktop.
Save junwen12221/a2227e2680eff16f1b149cad53d301a7 to your computer and use it in GitHub Desktop.
指令测试
package io.mycat;
import example.SQLFast;
import org.openjdk.jmh.annotations.*;
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;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.Throughput)//基准测试类型
@OutputTimeUnit(TimeUnit.SECONDS)//基准测试结果的时间类型
@Warmup(iterations = 6)//预热的迭代次数
@Threads(1)//测试线程数量
@State(Scope.Thread)//该状态为每个线程独享
//度量:iterations进行测试的轮次,time每轮进行的时长,timeUnit时长单位,batchSize批次数量
@Measurement(iterations = 5, time = -1, timeUnit = TimeUnit.SECONDS, batchSize = -1)
public class SQLBenchmark {
io.mycat.SQLParser parser;
io.mycat.SQLContext context;
byte[] srcBytes;
String src;
SQLFast.collector c;
//run
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(SQLBenchmark.class.getSimpleName())
.forks(1)
//.output("SQLBenchmark.log")//输出信息到文件
.build();
new Runner(opt).run();
}
@Setup
public void init() {
src = "SELECT a FROM ab , ee.ff AS f,(SELECT a FROM `schema_bb`.`tbl_bb`,(SELECT a FROM ccc AS c, `dddd`));";
srcBytes = src.getBytes(StandardCharsets.UTF_8);//20794
parser = new io.mycat.SQLParser();
context = new io.mycat.SQLContext();
c = new SQLFast.collector();
System.out.println("=> init");
}
@Benchmark
public int test1() {
int pos = 0;
int result = 0;
int len = srcBytes.length;
while (pos < len) {
result = srcBytes[pos] + result; // TODO: this line
pos++;
}
return result;
}
@Benchmark
public int test2() {
int pos = 0;
int result = 0;
int len = srcBytes.length;
while (pos < len) {
result = result<<8 | srcBytes[pos]; // TODO: this line
pos++;
}
return result;
}
@Benchmark
public int test3() {
int pos = 0;
int result = 0;
int len = srcBytes.length;
while (pos < len) {
result = srcBytes[pos]+1000000; // TODO: this line
pos++;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment