[url=http://openjdk.java.net/projects/code-tools/jmh/]JMH[/url]是OpenJDK开发的微基准测试框架。 编写完测试后,可以通过maven进行构建 mvn clean package,然后会得到一个可执行的独立jar包,执行java -jar target/benchmarks.jar可以运行测试程序。 如果直接在eclipse里运行测试程序会得到错误,
因为jmh用到了APT(Annotation Processing Tool),需要在eclipse中安装m2e-apt插件(在Eclipse Marketplace中就可以搜到)
[img]http://dl2.iteye.com/upload/attachment/0119/8907/cda24f6f-a7cb-3cfc-98b4-29051c8bedbc.png[/img]
安装完后,进行配置
[img]http://dl2.iteye.com/upload/attachment/0119/8909/1d4b5a50-88b7-3401-8d93-ee8f4dde6b78.png[/img]
然后就可以直接在eclipse中运行测试了。
Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList
at org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:97)
at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:103)
at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:256)
at org.openjdk.jmh.runner.Runner.run(Runner.java:206)
at net.szh.jmh.MyBenchmark.main(MyBenchmark.java:13)
因为jmh用到了APT(Annotation Processing Tool),需要在eclipse中安装m2e-apt插件(在Eclipse Marketplace中就可以搜到)
[img]http://dl2.iteye.com/upload/attachment/0119/8907/cda24f6f-a7cb-3cfc-98b4-29051c8bedbc.png[/img]
安装完后,进行配置
[img]http://dl2.iteye.com/upload/attachment/0119/8909/1d4b5a50-88b7-3401-8d93-ee8f4dde6b78.png[/img]
然后就可以直接在eclipse中运行测试了。