Java 8 Lambda的基准测试

本基准测试中,存在循环测试,先看一下官方的指导:Loops

对于此基准,创建了一个ArrayList,填充了100,000个随机整数,并实现了7种不同的方式来遍历,找到最大值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package org.benchmark.lambda;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
@Fork(2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class LamdbaTest {
private final int size = 1000000;

private final List<Integer> dataList= new ArrayList<>();

@Setup
public void setup(){
final Random random = new Random();

for(int i = 0; i < this.size; i++)
this.dataList.add(random.nextInt(this.size));
}

@Benchmark
public int iteratorMaxInteger() {
int max = Integer.MIN_VALUE;
for (final Iterator<Integer> it = this.dataList.iterator(); it.hasNext(); )
max = Integer.max(max, it.next());
return max;
}

@Benchmark
public int forEachLoopMaxInteger() {
int max = Integer.MIN_VALUE;
for (final Integer n : this.dataList)
max = Integer.max(max, n);
return max;
}

@Benchmark
public int forEachLambdaMaxInteger() {
final Wrapper wrapper = new Wrapper();
wrapper.inner = Integer.MIN_VALUE;
this.dataList.forEach(i -> this.helper(i, wrapper));
return wrapper.inner.intValue();
}

public static class Wrapper {
Integer inner;
}

private int helper(final int i, final Wrapper wrapper) {
wrapper.inner = Math.max(i, wrapper.inner);
return wrapper.inner;
}

@Benchmark
public int forMaxInteger() {
int max = Integer.MIN_VALUE;
for (int i = 0; i < this.size; i++)
max = Integer.max(max, this.dataList.get(i));
return max;
}

public int parallelStreamMaxInteger() {
final Optional<Integer> max = this.dataList.parallelStream().reduce(Integer::max);
return max.get();
}

@Benchmark
public int streamMaxInteger() {
final Optional<Integer> max = this.dataList.stream().reduce(Integer::max);
return max.get();
}

@Benchmark
public int lambdaMaxInteger() {
return this.dataList.stream().reduce(Integer.MIN_VALUE, (a, b) -> Integer.max(a, b));
}


public static void main(final String[] args) throws RunnerException {
final Options opt = new OptionsBuilder().include(LamdbaTest.class.getSimpleName()).build();

new Runner(opt).run();
}
}

测量结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.forEachLambdaMaxInteger

# Run progress: 0.00% complete, ETA 00:04:12
# Fork: 1 of 2
objc[41465]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x106c0c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x106c8c4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 6.259 ms/op
# Warmup Iteration 2: 5.041 ms/op
# Warmup Iteration 3: 4.805 ms/op
Iteration 1: 4.793 ms/op
Iteration 2: 4.915 ms/op
Iteration 3: 4.988 ms/op

# Run progress: 7.14% complete, ETA 00:04:09
# Fork: 2 of 2
objc[41490]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1042404c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1042c04e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 6.357 ms/op
# Warmup Iteration 2: 5.047 ms/op
# Warmup Iteration 3: 5.210 ms/op
Iteration 1: 5.079 ms/op
Iteration 2: 5.109 ms/op
Iteration 3: 5.152 ms/op


Result "org.benchmark.lambda.LamdbaTest.forEachLambdaMaxInteger":
5.006 ±(99.9%) 0.379 ms/op [Average]
(min, avg, max) = (4.793, 5.006, 5.152), stdev = 0.135
CI (99.9%): [4.627, 5.385] (assumes normal distribution)


# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.forEachLoopMaxInteger

# Run progress: 14.29% complete, ETA 00:03:48
# Fork: 1 of 2
objc[41515]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x10a0cf4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10a14f4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 1.260 ms/op
# Warmup Iteration 2: 1.284 ms/op
# Warmup Iteration 3: 1.285 ms/op
Iteration 1: 1.242 ms/op
Iteration 2: 1.266 ms/op
Iteration 3: 1.257 ms/op

# Run progress: 21.43% complete, ETA 00:03:29
# Fork: 2 of 2
objc[41542]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x10e2844c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10e3044e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 1.247 ms/op
# Warmup Iteration 2: 1.248 ms/op
# Warmup Iteration 3: 1.247 ms/op
Iteration 1: 1.259 ms/op
Iteration 2: 1.278 ms/op
Iteration 3: 1.262 ms/op


Result "org.benchmark.lambda.LamdbaTest.forEachLoopMaxInteger":
1.261 ±(99.9%) 0.033 ms/op [Average]
(min, avg, max) = (1.242, 1.261, 1.278), stdev = 0.012
CI (99.9%): [1.228, 1.293] (assumes normal distribution)


# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.forMaxInteger

# Run progress: 28.57% complete, ETA 00:03:09
# Fork: 1 of 2
objc[41560]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x10b2494c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10b2c94e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 0.995 ms/op
# Warmup Iteration 2: 0.974 ms/op
# Warmup Iteration 3: 0.967 ms/op
Iteration 1: 0.987 ms/op
Iteration 2: 0.984 ms/op
Iteration 3: 0.964 ms/op

# Run progress: 35.71% complete, ETA 00:02:50
# Fork: 2 of 2
objc[41585]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x10b4ed4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10b56d4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 0.978 ms/op
# Warmup Iteration 2: 0.966 ms/op
# Warmup Iteration 3: 0.981 ms/op
Iteration 1: 0.977 ms/op
Iteration 2: 0.971 ms/op
Iteration 3: 0.975 ms/op


Result "org.benchmark.lambda.LamdbaTest.forMaxInteger":
0.976 ±(99.9%) 0.024 ms/op [Average]
(min, avg, max) = (0.964, 0.976, 0.987), stdev = 0.008
CI (99.9%): [0.953, 1.000] (assumes normal distribution)


# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.iteratorMaxInteger

# Run progress: 42.86% complete, ETA 00:02:31
# Fork: 1 of 2
objc[41611]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1092fb4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10937b4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 1.265 ms/op
# Warmup Iteration 2: 1.252 ms/op
# Warmup Iteration 3: 1.260 ms/op
Iteration 1: 1.323 ms/op
Iteration 2: 1.283 ms/op
Iteration 3: 1.244 ms/op

# Run progress: 50.00% complete, ETA 00:02:12
# Fork: 2 of 2
objc[41632]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1091cf4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10a9f24e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 1.273 ms/op
# Warmup Iteration 2: 1.264 ms/op
# Warmup Iteration 3: 1.246 ms/op
Iteration 1: 1.270 ms/op
Iteration 2: 1.259 ms/op
Iteration 3: 1.299 ms/op


Result "org.benchmark.lambda.LamdbaTest.iteratorMaxInteger":
1.280 ±(99.9%) 0.080 ms/op [Average]
(min, avg, max) = (1.244, 1.280, 1.323), stdev = 0.029
CI (99.9%): [1.199, 1.360] (assumes normal distribution)


# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.lambdaMaxInteger

# Run progress: 57.14% complete, ETA 00:01:53
# Fork: 1 of 2
objc[41658]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x10292a4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1029aa4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 6.313 ms/op
# Warmup Iteration 2: 4.323 ms/op
# Warmup Iteration 3: 4.088 ms/op
Iteration 1: 4.222 ms/op
Iteration 2: 4.233 ms/op
Iteration 3: 4.731 ms/op

# Run progress: 64.29% complete, ETA 00:01:34
# Fork: 2 of 2
objc[41684]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1019874c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1031bc4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 6.169 ms/op
# Warmup Iteration 2: 4.303 ms/op
# Warmup Iteration 3: 3.918 ms/op
Iteration 1: 4.747 ms/op
Iteration 2: 4.181 ms/op
Iteration 3: 4.171 ms/op


Result "org.benchmark.lambda.LamdbaTest.lambdaMaxInteger":
4.381 ±(99.9%) 0.781 ms/op [Average]
(min, avg, max) = (4.171, 4.381, 4.747), stdev = 0.278
CI (99.9%): [3.600, 5.161] (assumes normal distribution)


# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.parallelStreamMaxInteger

# Run progress: 71.43% complete, ETA 00:01:15
# Fork: 1 of 2
objc[41710]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1006df4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10075f4e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 3.773 ms/op
# Warmup Iteration 2: 4.157 ms/op
# Warmup Iteration 3: 4.892 ms/op
Iteration 1: 5.224 ms/op
Iteration 2: 3.500 ms/op
Iteration 3: 3.650 ms/op

# Run progress: 78.57% complete, ETA 00:00:56
# Fork: 2 of 2
objc[41736]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x105e154c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x105e954e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 3.555 ms/op
# Warmup Iteration 2: 4.236 ms/op
# Warmup Iteration 3: 4.889 ms/op
Iteration 1: 3.629 ms/op
Iteration 2: 3.524 ms/op
Iteration 3: 3.363 ms/op


Result "org.benchmark.lambda.LamdbaTest.parallelStreamMaxInteger":
3.815 ±(99.9%) 1.956 ms/op [Average]
(min, avg, max) = (3.363, 3.815, 5.224), stdev = 0.698
CI (99.9%): [1.859, 5.771] (assumes normal distribution)


# JMH version: 1.22
# VM version: JDK 1.8.0_131, Java HotSpot(TM) 64-Bit Server VM, 25.131-b11
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
# VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58973:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
# Warmup: 3 iterations, 3 s each
# Measurement: 3 iterations, 3 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.benchmark.lambda.LamdbaTest.streamMaxInteger

# Run progress: 85.71% complete, ETA 00:00:38
# Fork: 1 of 2
objc[41758]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1048844c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1049044e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 6.520 ms/op
# Warmup Iteration 2: 5.507 ms/op
# Warmup Iteration 3: 5.196 ms/op
Iteration 1: 4.575 ms/op
Iteration 2: 4.715 ms/op
Iteration 3: 4.655 ms/op

# Run progress: 92.86% complete, ETA 00:00:19
# Fork: 2 of 2
objc[41784]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java (0x1011c34c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1029f14e0). One of the two will be used. Which one is undefined.
# Warmup Iteration 1: 6.057 ms/op
# Warmup Iteration 2: 4.827 ms/op
# Warmup Iteration 3: 4.908 ms/op
Iteration 1: 4.870 ms/op
Iteration 2: 4.834 ms/op
Iteration 3: 5.048 ms/op


Result "org.benchmark.lambda.LamdbaTest.streamMaxInteger":
4.783 ±(99.9%) 0.477 ms/op [Average]
(min, avg, max) = (4.575, 4.783, 5.048), stdev = 0.170
CI (99.9%): [4.306, 5.259] (assumes normal distribution)


# Run complete. Total time: 00:04:26

REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.

Benchmark Mode Cnt Score Error Units
LamdbaTest.forEachLambdaMaxInteger avgt 6 5.006 ± 0.379 ms/op
LamdbaTest.forEachLoopMaxInteger avgt 6 1.261 ± 0.033 ms/op
LamdbaTest.forMaxInteger avgt 6 0.976 ± 0.024 ms/op
LamdbaTest.iteratorMaxInteger avgt 6 1.280 ± 0.080 ms/op
LamdbaTest.lambdaMaxInteger avgt 6 4.381 ± 0.781 ms/op
LamdbaTest.parallelStreamMaxInteger avgt 6 3.815 ± 1.956 ms/op
LamdbaTest.streamMaxInteger avgt 6 4.783 ± 0.477 ms/op

Process finished with exit code 0

image-20200116111629735

注意:

Benchmark的测试方法尽量不要是void,要有返回值,如果实在不行,请使用blackhole。防止死代码消除带来的麻烦,使测量尽量准确。

坚持技术分享,您的支持将鼓励我继续创作!