Groovy压力测试模块 GBench
jopen
12年前
GBench 是 Groovy 的压力测试模块,提供 @Benchmark / Benchmark AST Transformation 用于实际程序测试以及 BenchmarkBuilder 用于微测试。
你可以通过在 groovy 文件中增加下面一行代码即可,想起请看 Installation
@Grab('com.googlecode.gbench:gbench:0.3.1-groovy-2.0') // v0.3.1 for Groovy 2.0
@Benchmark 实例:
import gbench.* class Task { @Benchmark void run() { // task } } /* Output: Task void run() user:847000 system:1777000 cpu:2624000 real:4918000 */
BenchmarkBuilder 实例:
import gbench.* new BenchmarkBuilder().run { 'StringBuilder' { def sb = new StringBuilder() sb.append('foo') sb.append('bar') sb.append('baz') sb.toString() } 'StringBuffer' { def sb = new StringBuffer() sb.append('foo') sb.append('bar') sb.append('baz') sb.toString() } }.prettyPrint() /* Output: Environment =========== * Groovy: 2.0.0 * JVM: Java HotSpot(TM) 64-Bit Server VM (23.0-b15, Oracle Corporation) * JRE: 1.7.0_04-ea * Total Memory: 99.4375 MB * Maximum Memory: 1169.8125 MB * OS: Mac OS X (10.7.3, amd64) Options ======= * Warm Up: Auto * CPU Time Measurement: On user system cpu real StringBuilder 236 0 236 237 StringBuffer 263 0 263 267 */http://code.google.com/p/gbench/