Java中的BenchMark框架与Criterium类似

Dav*_*ams 2 java benchmarking clojure

我正在寻找一个Java基准测试库.我对Clojure 中的Criterium基准测试库的功能非常熟悉和满意.它具有如下功能:

* Statistical processing of multiple evaluations
* Inclusion of a warm-up period, designed to allow the JIT compiler to optimise its code
* Purging of gc before testing, to isolate timings from GC state prior to testing  
* A final forced GC after testing to estimate impact of cleanup on the timing results
Run Code Online (Sandbox Code Playgroud)

它的界面非常友好

(bench expr & opts)
Run Code Online (Sandbox Code Playgroud)

其中打印摘要统计报告,例如:

 => (bench (Thread/sleep 1000))

               Execution time mean : 1.000803 sec
      Execution time std-deviation : 328.501853 us
     Execution time lower quantile : 1.000068 sec ( 2.5%)
     Execution time upper quantile : 1.001186 sec (97.5%)
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个类似的Java库,也许是一个公开一个Bench方法,比如一个Callable,或一个Runnable,并打印一个类似的报告.如:

  BenchMark.bench(new Callable<String>() {
      @Override
      public String call() { ... }
  })
Run Code Online (Sandbox Code Playgroud)

有没有人知道一个功能齐全,开源免费的啤酒库,这样做?也许还包括内存统计?

ass*_*ias 7

在我看来,目前最好的基准测试库之一是jmh.它由Oracle人员积极开发,它是开源的,它用于微开放openJDK的部分,包括并发API和JavaFX.

输出非常全面,可以包括每个操作的时间,每毫秒的操作数,置信区间等.您还可以选择引入线程,争用,共享等.