<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=JMH_Benchmark</id>
	<title>JMH Benchmark - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=JMH_Benchmark"/>
	<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;action=history"/>
	<updated>2026-06-02T22:05:29Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=5088&amp;oldid=prev</id>
		<title>2025年7月31日 (四) 01:31 Riguz</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=5088&amp;oldid=prev"/>
		<updated>2025-07-31T01:31:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2025年7月31日 (四) 01:31的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l66&quot;&gt;第66行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第66行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Java]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Java]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:JVM]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Performance]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Riguz</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=4005&amp;oldid=prev</id>
		<title>Riguz：​Riguz移动页面Blog:使用JMH进行Benchmark测试至JMH Benchmark，不留重定向</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=4005&amp;oldid=prev"/>
		<updated>2024-01-18T07:22:37Z</updated>

		<summary type="html">&lt;p&gt;Riguz移动页面&lt;a href=&quot;/index.php?title=Blog:%E4%BD%BF%E7%94%A8JMH%E8%BF%9B%E8%A1%8CBenchmark%E6%B5%8B%E8%AF%95&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Blog:使用JMH进行Benchmark测试（页面不存在）&quot;&gt;Blog:使用JMH进行Benchmark测试&lt;/a&gt;至&lt;a href=&quot;/JMH_Benchmark&quot; title=&quot;JMH Benchmark&quot;&gt;JMH Benchmark&lt;/a&gt;，不留重定向&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2024年1月18日 (四) 07:22的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Riguz</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=4004&amp;oldid=prev</id>
		<title>2024年1月18日 (四) 07:22 Riguz</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=4004&amp;oldid=prev"/>
		<updated>2024-01-18T07:22:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2024年1月18日 (四) 07:22的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l64&quot;&gt;第64行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第64行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://tutorials.jenkov.com/java-performance/jmh.html#why-are-java-microbenchmarks-hard&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://tutorials.jenkov.com/java-performance/jmh.html#why-are-java-microbenchmarks-hard&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* https://www.jianshu.com/p/192b782c31bc&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* https://www.jianshu.com/p/192b782c31bc&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Java]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Riguz</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=2576&amp;oldid=prev</id>
		<title>imported&gt;Riguz：​JMH是一个测试Java程序性能的工具，比如我们现在要测试一下JDK8自带的Base64和[另一个实现](http://www.java2s.com/Code/Java/Development-Class/AfastandmemoryefficientclasstoencodeanddecodetoandfromBASE64infullaccordancewithRFC2045.htm)的性能。</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=JMH_Benchmark&amp;diff=2576&amp;oldid=prev"/>
		<updated>2018-05-09T00:00:00Z</updated>

		<summary type="html">&lt;p&gt;JMH是一个测试Java程序性能的工具，比如我们现在要测试一下JDK8自带的Base64和[另一个实现](http://www.java2s.com/Code/Java/Development-Class/AfastandmemoryefficientclasstoencodeanddecodetoandfromBASE64infullaccordancewithRFC2045.htm)的性能。&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;JMH是一个测试Java程序性能的工具，比如我们现在要测试一下JDK8自带的Base64和[http://www.java2s.com/Code/Java/Development-Class/AfastandmemoryefficientclasstoencodeanddecodetoandfromBASE64infullaccordancewithRFC2045.htm 另一个实现]的性能。&lt;br /&gt;
先看看 build.gradle 中怎么写：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;groovy&amp;quot;&amp;gt;&lt;br /&gt;
group &amp;#039;riguz&amp;#039;&lt;br /&gt;
version &amp;#039;1.0-SNAPSHOT&amp;#039;&lt;br /&gt;
&lt;br /&gt;
apply plugin: &amp;#039;java&amp;#039;&lt;br /&gt;
&lt;br /&gt;
sourceCompatibility = 1.8&lt;br /&gt;
&lt;br /&gt;
sourceSets {&lt;br /&gt;
    jmh&lt;br /&gt;
}&lt;br /&gt;
repositories {&lt;br /&gt;
    mavenCentral()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
dependencies {&lt;br /&gt;
    jmhCompile project&lt;br /&gt;
    jmhCompile &amp;#039;org.openjdk.jmh:jmh-core:1.21&amp;#039;&lt;br /&gt;
    jmhCompile &amp;#039;org.openjdk.jmh:jmh-generator-annprocess:1.21&amp;#039;&lt;br /&gt;
    jmhCompile group: &amp;#039;junit&amp;#039;, name: &amp;#039;junit&amp;#039;, version: &amp;#039;4.12&amp;#039;&lt;br /&gt;
    testCompile group: &amp;#039;junit&amp;#039;, name: &amp;#039;junit&amp;#039;, version: &amp;#039;4.12&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
task jmh(type: JavaExec, description: &amp;#039;Executing JMH benchmarks&amp;#039;) {&lt;br /&gt;
    classpath = sourceSets.jmh.runtimeClasspath&lt;br /&gt;
    main = &amp;#039;org.openjdk.jmh.Main&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
然后写一个类：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Benchmark&lt;br /&gt;
    @Warmup(iterations = 1, time = 5)&lt;br /&gt;
    @Measurement(iterations = 1, time = 5)&lt;br /&gt;
    public void encodeWithJdk() {&lt;br /&gt;
        final byte[] bytes = Dream.text.getBytes();&lt;br /&gt;
        byte[] encoded = Base64.getEncoder().encode(bytes);&lt;br /&gt;
        byte[] decoded = Base64.getDecoder().decode(encoded);&lt;br /&gt;
        assertTrue(Arrays.equals(bytes, decoded));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Benchmark&lt;br /&gt;
    @Warmup(iterations = 1, time = 5)&lt;br /&gt;
    @Measurement(iterations = 1, time = 5)&lt;br /&gt;
    public void encodeWithBase64Codec() throws IOException {&lt;br /&gt;
        final byte[] bytes = Dream.text.getBytes();&lt;br /&gt;
        byte[] encoded = Base64Codec.encodeToByte(bytes, true);&lt;br /&gt;
        byte[] decoded = Base64Codec.decodeFast(encoded, encoded.length);&lt;br /&gt;
        assertTrue(Arrays.equals(bytes, decoded));&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
其中Dream.text是一个很长的字符串。执行gradle的jmh task之后，可以得到结果&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Benchmark                               Mode  Cnt   Score   Error  Units&lt;br /&gt;
Base64BenchMark.encodeWithBase64Codec  thrpt    5  15.296 ± 2.538  ops/s&lt;br /&gt;
Base64BenchMark.encodeWithJdk          thrpt    5  13.029 ± 1.563  ops/s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
看样子要比JDK的实现强一丢丢，当然只是在上面的这种情况之下。差距并不大。&lt;br /&gt;
&lt;br /&gt;
参考:&lt;br /&gt;
&lt;br /&gt;
* http://tutorials.jenkov.com/java-performance/jmh.html#why-are-java-microbenchmarks-hard&lt;br /&gt;
* https://www.jianshu.com/p/192b782c31bc&lt;/div&gt;</summary>
		<author><name>imported&gt;Riguz</name></author>
	</entry>
</feed>