一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java Benchmark 基準測試的實例詳解

Java Benchmark 基準測試的實例詳解

2020-12-16 13:30hpgary Java教程

這篇文章主要介紹了Java Benchmark 基準測試的實例詳解的相關資料,這里提供實例幫助大家學習理解這部分內容,需要的朋友可以參考下

Java Benchmark 基準測試的實例詳解

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
 
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
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.Threads;
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;
 
@BenchmarkMode(Mode.Throughput)//基準測試類型
@OutputTimeUnit(TimeUnit.SECONDS)//基準測試結果的時間類型
@Warmup(iterations = 3)//預熱的迭代次數
@Threads(2)//測試線程數量
@State(Scope.Thread)//該狀態為每個線程獨享
//度量:iterations進行測試的輪次,time每輪進行的時長,timeUnit時長單位,batchSize批次數量
@Measurement(iterations = 2, time = -1, timeUnit = TimeUnit.SECONDS, batchSize = -1)
public class InstructionsBenchmark{
  static int staticPos = 0;
  //String src = "SELECT a FROM ab       , ee.ff AS f,(SELECT a FROM `schema_bb`.`tbl_bb`,(SELECT a FROM ccc AS c, `dddd`));";
  final byte[] srcBytes = {83, 69, 76, 69, 67, 84, 32, 97, 32, 70, 82, 79, 77, 32, 97, 98, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 44, 32, 101, 101, 46, 102, 102, 32, 65, 83, 32, 102, 44, 40, 83, 69, 76, 69, 67, 84, 32, 97, 32, 70, 82, 79, 77, 32, 96, 115, 99, 104, 101, 109, 97, 95, 98, 98, 96, 46, 96, 116, 98, 108, 95, 98, 98, 96, 44, 40, 83, 69, 76, 69, 67, 84, 32, 97, 32, 70, 82, 79, 77, 32, 99, 99, 99, 32, 65, 83, 32, 99, 44, 32, 96, 100, 100, 100, 100, 96, 41, 41, 59};
  int len = srcBytes.length;
  byte[] array = new byte[8192];
  int memberVariable = 0;
 
  //run
  public static void main(String[] args) throws RunnerException {
    Options opt = new OptionsBuilder()
        .include(InstructionsBenchmark.class.getSimpleName())
        .forks(1)
        //   使用之前要安裝hsdis
        //-XX:-TieredCompilation 關閉分層優化 -server
        //-XX:+LogCompilation 運行之后項目路徑會出現按照測試順序輸出hotspot_pid<PID>.log文件,可以使用JITWatch進行分析,可以根據最后運行的結果的順序按文件時間找到對應的hotspot_pid<PID>.log文件
        .jvmArgs("-XX:+UnlockDiagnosticVMOptions", "-XX:+LogCompilation", "-XX:+TraceClassLoading", "-XX:+PrintAssembly")
        // .addProfiler(CompilerProfiler.class)  // report JIT compiler profiling via standard MBeans
        // .addProfiler(GCProfiler.class)  // report GC time
        // .addProfiler(StackProfiler.class) // report method stack execution profile
        // .addProfiler(PausesProfiler.class)
        /*
        WinPerfAsmProfiler
        You must install Windows Performance Toolkit. Once installed, locate directory with xperf.exe file
        and either add it to PATH environment variable, or set it to jmh.perfasm.xperf.dir system property.
         */
        //.addProfiler(WinPerfAsmProfiler.class)
        //更多Profiler,請看JMH介紹
        //.output("InstructionsBenchmark.log")//輸出信息到文件
        .build();
    new Runner(opt).run();
  }
 
 
  //空循環 對照項
  @Benchmark
  public int emptyLoop() {
    int pos = 0;
    while (pos < len) {
      ++pos;
    }
    return pos;
  }
 
  @Benchmark
  public int increment() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      ++result;
      ++pos;
    }
    return result;
  }
 
  @Benchmark
  public int decrement() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      --result;
      ++pos;
    }
    return result;
  }
 
  @Benchmark
  public int ifElse() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      if (pos == 10) {
        ++result;
        ++pos;
      } else {
        ++pos;
      }
    }
    return result;
  }
 
  @Benchmark
  public int ifElse2() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      if (pos == 10) {
        ++result;
        ++pos;
      } else if (pos == 20) {
        ++result;
        ++pos;
      } else {
        ++pos;
      }
    }
    return result;
  }
 
  @Benchmark
  public int ifnotElse() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      if (pos != 10) {
        ++pos;
      } else {
        ++result;
        ++pos;
      }
    }
    return result;
  }
 
  @Benchmark
  public int ifLessthanElse() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      if (pos < 10) {
        ++pos;
      } else {
        ++result;
        ++pos;
      }
    }
    return result;
  }
 
  @Benchmark
  public int ifGreaterthanElse() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      if (pos > 10) {
        ++pos;
      } else {
        ++result;
        ++pos;
      }
    }
    return result;
  }
 
  @Benchmark
  public int readMemberVariable_a_byteArray() {
    int pos = 0;
    int result = 0;
    while (pos < len) {
      result = srcBytes[pos];
      pos++;
    }
    return result;
  }
 
}

 ops/time:標識每秒鐘執行的次數

 依賴jar包:

?
1
2
3
4
5
6
7
8
9
10
11
<dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-core</artifactId>
      <version>${jmh.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-generator-annprocess</artifactId>
      <version>${jmh.version}</version>
      <scope>provided</scope>
    </dependency>
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>run-benchmarks</id>
            <phase>integration-test</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <classpathScope>test</classpathScope>
              <executable>java</executable>
              <arguments>
                <argument>-classpath</argument>
                <classpath />
                <argument>org.openjdk.jmh.Main</argument>
                <argument>.*</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

以上就是Java Benchmark 基準測試,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

原文鏈接:http://hpgary.iteye.com/blog/2360981

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 四虎1515hh.com | 和日本免费不卡在线v | 91久久青青青国产免费 | 美女操批 | 久久精品国产清白在天天线 | 色中文字幕 | 暴露狂婷婷 | 亚洲高清国产品国语在线观看 | 欧美同性videos | 国产亚洲精品一区在线播 | 男人的视频网站 | 俄罗斯极品h在线 | 国产精品一区二区国产 | 500福利第一巨人导航 | 91精品国产亚一区二区三区 | 亚洲一区二区成人 | 亚洲成人在线播放 | 狠狠色婷婷日日综合五月 | 四虎免费在线观看 | 草草精品视频 | 国产高清在线播放刘婷91 | 亚洲AV无码一区二区三区乱子伦 | 欧美精品久久久亚洲 | 插得好爽 | 成人小视频在线观看 | 国产成人lu在线视频 | 国产精品久久久久久搜索 | 欧洲vodafone精品性 | 国产播放器一区 | 人人澡人 | 欧美影院一区二区三区 | 四虎永久视频 | 午夜勾魂曲 | 91对白在线 | 91污无限制破解安卓2021 | 日韩在线a视频免费播放 | 日韩欧美国产综合精品 | 免费看男女污污完整版 | 天天夜夜啦啦啦 | 四川女人偷人真实视频 | 欧美国产精品 |