v2 blackholes, java8
This commit is contained in:
parent
720f0f07a8
commit
17fb67b7ad
4 changed files with 88 additions and 36 deletions
10
pom.xml
10
pom.xml
|
|
@ -9,8 +9,8 @@
|
|||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
|
@ -41,9 +41,9 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<compilerVersion>9</compilerVersion>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<compilerVersion>8</compilerVersion>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
|||
45
report.md
Normal file
45
report.md
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
**cStyle**
|
||||
```
|
||||
23,57% 0x0000000112765de8: ;*aaload {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - java.util.ArrayList::elementData@5 (line 411)
|
||||
; - java.util.ArrayList::get@11 (line 428)
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::cStyle@20 (line 35)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_cStyle_jmhTest::cStyle_avgt_jmhStub@19 (line 193)
|
||||
|
||||
30,39% 0x0000000112765e00: ;*getfield coder {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - java.lang.String::coder@7 (line 4556)
|
||||
; - java.lang.String::length@6 (line 1499)
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::cStyle@28 (line 35)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_cStyle_jmhTest::cStyle_avgt_jmhStub@19 (line 193)
|
||||
|
||||
27,83% 0x0000000112765e28: ;*getfield coder {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - java.lang.String::coder@7 (line 4556)
|
||||
; - java.lang.String::length@6 (line 1499)
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::cStyle@28 (line 35)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_cStyle_jmhTest::cStyle_avgt_jmhStub@19 (line 193)
|
||||
|
||||
5,18% 0x0000000112765e3c: ;*if_icmpge {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::cStyle@10 (line 34)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_cStyle_jmhTest::cStyle_avgt_jmhStub@19 (line 193)
|
||||
```
|
||||
|
||||
**enhancedForLoop**
|
||||
```
|
||||
29,09% 0x0000000113e5a748: ;*aaload {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - java.util.ArrayList$Itr::next@64 (line 975)
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::enhancedForLoop@25 (line 52)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_enhancedForLoop_jmhTest::enhancedForLoop_avgt_jmhStub@19 (line 193)
|
||||
|
||||
23,18% 0x0000000113e5a760: ;*getfield coder {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - java.lang.String::coder@7 (line 4556)
|
||||
; - java.lang.String::length@6 (line 1499)
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::enhancedForLoop@38 (line 53)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_enhancedForLoop_jmhTest::enhancedForLoop_avgt_jmhStub@19 (line 193)
|
||||
|
||||
17,19% 0x0000000113e5a788: ;*getfield coder {reexecute=0 rethrow=0 return_oop=0}
|
||||
; - java.lang.String::coder@7 (line 4556)
|
||||
; - java.lang.String::length@6 (line 1499)
|
||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::enhancedForLoop@38 (line 53)
|
||||
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_enhancedForLoop_jmhTest::enhancedForLoop_avgt_jmhStub@19 (line 193)
|
||||
```
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.github.shautvast.benchmarks.loops;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
import org.openjdk.jmh.profile.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
|
|
@ -13,10 +14,9 @@ import java.util.concurrent.TimeUnit;
|
|||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Fork(value = 1)
|
||||
@State(Scope.Thread)
|
||||
public class LoopBenchmark {
|
||||
|
||||
@org.openjdk.jmh.annotations.State(Scope.Thread)
|
||||
public static class State {
|
||||
final static int LIST_SIZE = 1000;
|
||||
List<String> list = new ArrayList<>(LIST_SIZE);
|
||||
|
||||
|
|
@ -26,38 +26,45 @@ public class LoopBenchmark {
|
|||
list.add(UUID.randomUUID().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void forLoop(Blackhole bh) {
|
||||
for (int i = 0; i < LIST_SIZE; i++) {
|
||||
bh.consume(list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public long cStyle(LoopBenchmark.State state) {
|
||||
long totalLength = 0;
|
||||
for (int i = 0; i < State.LIST_SIZE; i++) {
|
||||
totalLength += state.list.get(i).length();
|
||||
public void whileLoop(Blackhole bh) {
|
||||
int i = 0;
|
||||
while (i < LIST_SIZE) {
|
||||
bh.consume(list.get(i));
|
||||
i++;
|
||||
}
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public long iterator(LoopBenchmark.State state) {
|
||||
long totalLength = 0;
|
||||
for (Iterator<String> iterator = state.list.iterator(); iterator.hasNext(); ) {
|
||||
totalLength += iterator.next().length();
|
||||
public void iterator(Blackhole bh) {
|
||||
for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); ) {
|
||||
bh.consume(iterator.next());
|
||||
}
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public long enhancedForLoop(LoopBenchmark.State state) {
|
||||
long totalLength = 0;
|
||||
for (String element : state.list) {
|
||||
totalLength += element.length();
|
||||
public void enhancedForLoop(Blackhole bh) {
|
||||
for (String element : list) {
|
||||
bh.consume(element.length());
|
||||
}
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public long stream(LoopBenchmark.State state) {
|
||||
return state.list.stream().mapToLong(String::length).sum();
|
||||
public void stream(Blackhole bh) {
|
||||
list.stream().forEach(bh::consume);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void forEach(Blackhole bh) {
|
||||
list.forEach(bh::consume);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue