避开Java基准测试中的陷阱
Avoiding Benchmarking Pitfalls on the JVM
基准测试看似简单,但是由于JVM会在运行时做优化,可能使得基准测试的结果失去意义。
比如JVM如果“看到”接口只有一种实现时,会对接口方法的调用做优化。 如果在后续运行中“看到”很多的接口实现时,则会抛弃掉之前的优化。 这会导致对第二个接口实现的benchmark结果变得不准确。 其它JVM优化手段还有dead-code elimination、constant folding等等。
所谓基准测试,意味着有baseline,有对比,JVM的优化会导致对比的某一方得到了“不公平的”优待,使得对比的结果失去了意义。
文章推荐使用jmh来做基准测试。
it was developed as part of the OpenJDK project
JMH is popular for writing microbenchmarks, that is, benchmarks that stress a very specific piece of code. …
...
工具推荐:TitleCap
推荐一个可以自动将英文标题首字母大写的工具。 支持多种首字母大写规则,包括Chicago Manual of Style,
- Always capitalize the first and the last word.
- Capitalize all nouns, pronouns, adjectives, verbs, adverbs, and subordinate conjunctions (“as”, “because”, “although”, “if”, etc.).
- Lowercase all articles, coordinate conjunctions (“and”, “or”, “nor”), and prepositions regardless of length, when they are other than the first or last word.
- Lowercase the “to” in an infinitive.