v2 blackholes, java8
This commit is contained in:
parent
720f0f07a8
commit
17fb67b7ad
4 changed files with 88 additions and 36 deletions
10
log
10
log
|
|
@ -569,11 +569,11 @@ c2, level 4, com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_e
|
||||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::enhancedForLoop@38 (line 53)
|
; - 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)
|
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_enhancedForLoop_jmhTest::enhancedForLoop_avgt_jmhStub@19 (line 193)
|
||||||
1,81% 0x0000000113e5a784: 210c 40b9
|
1,81% 0x0000000113e5a784: 210c 40b9
|
||||||
17,19% 0x0000000113e5a788: ;*getfield coder {reexecute=0 rethrow=0 return_oop=0}
|
17,19% 0x0000000113e5a788: ;*getfield coder {reexecute=0 rethrow=0 return_oop=0}
|
||||||
; - java.lang.String::coder@7 (line 4556)
|
; - java.lang.String::coder@7 (line 4556)
|
||||||
; - java.lang.String::length@6 (line 1499)
|
; - java.lang.String::length@6 (line 1499)
|
||||||
; - com.github.shautvast.benchmarks.loops.LoopBenchmark::enhancedForLoop@38 (line 53)
|
; - 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)
|
; - com.github.shautvast.benchmarks.loops.jmh_generated.LoopBenchmark_enhancedForLoop_jmhTest::enhancedForLoop_avgt_jmhStub@19 (line 193)
|
||||||
17,19% 0x0000000113e5a788: 8642 c039 | 2128 c61a
|
17,19% 0x0000000113e5a788: 8642 c039 | 2128 c61a
|
||||||
0,01% 0x0000000113e5a790: ;*iadd {reexecute=0 rethrow=0 return_oop=0}
|
0,01% 0x0000000113e5a790: ;*iadd {reexecute=0 rethrow=0 return_oop=0}
|
||||||
; - java.util.ArrayList$Itr::next@53 (line 974)
|
; - java.util.ArrayList$Itr::next@53 (line 974)
|
||||||
|
|
|
||||||
10
pom.xml
10
pom.xml
|
|
@ -9,8 +9,8 @@
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>20</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>20</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
@ -41,9 +41,9 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<compilerVersion>9</compilerVersion>
|
<compilerVersion>8</compilerVersion>
|
||||||
<source>9</source>
|
<source>8</source>
|
||||||
<target>9</target>
|
<target>8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<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;
|
package com.github.shautvast.benchmarks.loops;
|
||||||
|
|
||||||
import org.openjdk.jmh.annotations.*;
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
import org.openjdk.jmh.infra.Blackhole;
|
||||||
import org.openjdk.jmh.profile.*;
|
import org.openjdk.jmh.profile.*;
|
||||||
import org.openjdk.jmh.runner.Runner;
|
import org.openjdk.jmh.runner.Runner;
|
||||||
import org.openjdk.jmh.runner.RunnerException;
|
import org.openjdk.jmh.runner.RunnerException;
|
||||||
|
|
@ -13,51 +14,57 @@ import java.util.concurrent.TimeUnit;
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
@Fork(value = 1)
|
@Fork(value = 1)
|
||||||
|
@State(Scope.Thread)
|
||||||
public class LoopBenchmark {
|
public class LoopBenchmark {
|
||||||
|
|
||||||
@org.openjdk.jmh.annotations.State(Scope.Thread)
|
final static int LIST_SIZE = 1000;
|
||||||
public static class State {
|
List<String> list = new ArrayList<>(LIST_SIZE);
|
||||||
final static int LIST_SIZE = 1000;
|
|
||||||
List<String> list = new ArrayList<>(LIST_SIZE);
|
|
||||||
|
|
||||||
@Setup(Level.Iteration)
|
@Setup(Level.Iteration)
|
||||||
public void doSetup() {
|
public void doSetup() {
|
||||||
for (int i = 0; i < LIST_SIZE; i++) {
|
for (int i = 0; i < LIST_SIZE; i++) {
|
||||||
list.add(UUID.randomUUID().toString());
|
list.add(UUID.randomUUID().toString());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public long cStyle(LoopBenchmark.State state) {
|
public void forLoop(Blackhole bh) {
|
||||||
long totalLength = 0;
|
for (int i = 0; i < LIST_SIZE; i++) {
|
||||||
for (int i = 0; i < State.LIST_SIZE; i++) {
|
bh.consume(list.get(i));
|
||||||
totalLength += state.list.get(i).length();
|
|
||||||
}
|
}
|
||||||
return totalLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public long iterator(LoopBenchmark.State state) {
|
public void whileLoop(Blackhole bh) {
|
||||||
long totalLength = 0;
|
int i = 0;
|
||||||
for (Iterator<String> iterator = state.list.iterator(); iterator.hasNext(); ) {
|
while (i < LIST_SIZE) {
|
||||||
totalLength += iterator.next().length();
|
bh.consume(list.get(i));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return totalLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public long enhancedForLoop(LoopBenchmark.State state) {
|
public void iterator(Blackhole bh) {
|
||||||
long totalLength = 0;
|
for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); ) {
|
||||||
for (String element : state.list) {
|
bh.consume(iterator.next());
|
||||||
totalLength += element.length();
|
|
||||||
}
|
}
|
||||||
return totalLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public long stream(LoopBenchmark.State state) {
|
public void enhancedForLoop(Blackhole bh) {
|
||||||
return state.list.stream().mapToLong(String::length).sum();
|
for (String element : list) {
|
||||||
|
bh.consume(element.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
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 {
|
public static void main(String[] args) throws RunnerException {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue