最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java Benchmark 基準(zhǔn)測試的實(shí)例詳解

 更新時間:2017年08月16日 10:25:02   投稿:lqh  
這篇文章主要介紹了Java Benchmark 基準(zhǔn)測試的實(shí)例詳解的相關(guān)資料,這里提供實(shí)例幫助大家學(xué)習(xí)理解這部分內(nèi)容,需要的朋友可以參考下

Java Benchmark 基準(zhǔn)測試的實(shí)例詳解

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)//基準(zhǔn)測試類型 
@OutputTimeUnit(TimeUnit.SECONDS)//基準(zhǔn)測試結(jié)果的時間類型 
@Warmup(iterations = 3)//預(yù)熱的迭代次數(shù) 
@Threads(2)//測試線程數(shù)量 
@State(Scope.Thread)//該狀態(tài)為每個線程獨(dú)享 
//度量:iterations進(jìn)行測試的輪次,time每輪進(jìn)行的時長,timeUnit時長單位,batchSize批次數(shù)量 
@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 關(guān)閉分層優(yōu)化 -server 
        //-XX:+LogCompilation 運(yùn)行之后項目路徑會出現(xiàn)按照測試順序輸出hotspot_pid<PID>.log文件,可以使用JITWatch進(jìn)行分析,可以根據(jù)最后運(yùn)行的結(jié)果的順序按文件時間找到對應(yīng)的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(); 
  } 
 
 
  //空循環(huán) 對照項 
  @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:標(biāo)識每秒鐘執(zhí)行的次數(shù)

 依賴jar包:

<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> 
<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 基準(zhǔn)測試,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • Spring內(nèi)置定時任務(wù)調(diào)度@Scheduled使用詳解

    Spring內(nèi)置定時任務(wù)調(diào)度@Scheduled使用詳解

    這篇文章主要介紹了Spring內(nèi)置定時任務(wù)調(diào)度@Scheduled使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-12-12
  • maven配置多個鏡像的實(shí)現(xiàn)方法

    maven配置多個鏡像的實(shí)現(xiàn)方法

    這篇文章主要介紹了maven配置多個鏡像的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • Java并發(fā)編程中的ReentrantLock類詳解

    Java并發(fā)編程中的ReentrantLock類詳解

    這篇文章主要介紹了Java并發(fā)編程中的ReentrantLock類詳解,ReentrantLock是juc.locks包中的一個獨(dú)占式可重入鎖,相比synchronized,它可以創(chuàng)建多個條件等待隊列,還支持公平/非公平鎖、可中斷、超時、輪詢等特性,需要的朋友可以參考下
    2023-12-12
  • JavaWeb中HttpSession中表單的重復(fù)提交示例

    JavaWeb中HttpSession中表單的重復(fù)提交示例

    這篇文章主要介紹了JavaWeb中HttpSession中表單的重復(fù)提交,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-03-03
  • Java實(shí)現(xiàn)PDF轉(zhuǎn)為Word文檔的示例代碼

    Java實(shí)現(xiàn)PDF轉(zhuǎn)為Word文檔的示例代碼

    眾所周知,PDF文檔除了具有較強(qiáng)穩(wěn)定性和兼容性外,?還具有較強(qiáng)的安全性,在工作中可以有效避免別人無意中對文檔內(nèi)容進(jìn)行修改。本文將分為以下兩部分介紹如何在保持布局的情況下將PDF轉(zhuǎn)為Word文檔,希望對大家有所幫助
    2023-01-01
  • Spring與Hibernate整合事務(wù)管理的理解

    Spring與Hibernate整合事務(wù)管理的理解

    這篇文章主要介紹了Spring與Hibernate整合事務(wù)管理的理解的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • RocketMQ延遲消息超詳細(xì)講解

    RocketMQ延遲消息超詳細(xì)講解

    延時消息是指發(fā)送到 RocketMQ 后不會馬上被消費(fèi)者拉取到,而是等待固定的時間,才能被消費(fèi)者拉取到。延時消息的使用場景很多,比如電商場景下關(guān)閉超時未支付的訂單,某些場景下需要在固定時間后發(fā)送提示消息
    2023-02-02
  • SpringBoot深入講解單元測試與熱部署應(yīng)用

    SpringBoot深入講解單元測試與熱部署應(yīng)用

    這篇文章介紹了SpringBoot單元測試與熱部署,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • springSecurity之AuthenticationProvider用法解析

    springSecurity之AuthenticationProvider用法解析

    這篇文章主要介紹了springSecurity之AuthenticationProvider用法解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java獲取網(wǎng)絡(luò)文件并插入數(shù)據(jù)庫的代碼

    Java獲取網(wǎng)絡(luò)文件并插入數(shù)據(jù)庫的代碼

    抓取各大網(wǎng)站的數(shù)據(jù)插入數(shù)據(jù)庫,這樣就不用為沒有數(shù)據(jù)而煩惱了
    2010-06-06

最新評論

洛川县| 霍城县| 黄冈市| 南木林县| 灵山县| 万山特区| 栾城县| 阿尔山市| 黔东| 海晏县| 江华| 广汉市| 宜城市| 古田县| 宁波市| 常州市| 手游| 巫溪县| 崇左市| 绩溪县| 芮城县| 陆川县| 大城县| 龙州县| 城市| 白河县| 长海县| 元谋县| 镇江市| 郁南县| 鄯善县| 嘉善县| 秦安县| 屯留县| 镇平县| 加查县| 柳河县| 长沙县| 嵩明县| 图木舒克市| 望都县|