|
29 | 29 | * <li>(DISCOURAGED) List.stream - always incurs allocation overhead - usually unnecessary |
30 | 30 | * <li>(DISCOURAGED) List.parallelStream - heavy allocation overhead - only beneficial when |
31 | 31 | * working with sets (uncommon in the java agent) |
32 | | - * <li><code>Java 17 - MacBook M1 - 8 threads |
| 32 | + * <li> |
| 33 | + * </ul> |
| 34 | + * <code>Java 17 - MacBook M1 - 8 threads |
33 | 35 | * Benchmark (listSpec) Mode Cnt Score Error Units |
34 | 36 | * ListIterationBenchmark.cstyleFor_inline COLLECTIONS_EMPTY_LIST thrpt 3 9066154714.207 ± 3993855570.335 ops/s |
35 | 37 | * ListIterationBenchmark.cstyleFor:gc.alloc.rate.norm COLLECTIONS_EMPTY_LIST thrpt 3 ≈ 10⁻⁷ B/op |
@@ -335,75 +337,74 @@ public enum ListSpec { |
335 | 337 |
|
336 | 338 | @Param ListSpec listSpec; |
337 | 339 |
|
338 | | - @Benchmark |
339 | | - public void forEach_inline() { |
340 | | - this.listSpec.list.forEach(Element::manipulate_inline); |
341 | | - } |
342 | | - |
343 | | - @Benchmark |
344 | | - public void forEach_dont_inline() { |
345 | | - this.listSpec.list.forEach(Element::manipulate_dont_inline); |
346 | | - } |
347 | | - |
348 | | - @Benchmark |
349 | | - public void enhancedFor_inline() { |
350 | | - // Enhanced for-loop is just syntax sugar for an Iterator |
351 | | - for ( Element e : this.listSpec.list ) { |
352 | | - e.manipulate_inline(); |
353 | | - } |
354 | | - } |
355 | | - |
356 | | - @Benchmark |
357 | | - public void enhancedFor_dont_inline() { |
358 | | - // Enhanced for-loop is just syntax sugar for an Iterator |
359 | | - for ( Element e : this.listSpec.list ) { |
360 | | - e.manipulate_dont_inline(); |
361 | | - } |
362 | | - } |
363 | | - |
364 | | - @Benchmark |
365 | | - public void iterator_inline() { |
366 | | - for ( Iterator<Element> iter = this.listSpec.list.iterator(); iter.hasNext(); ) { |
367 | | - iter.next().manipulate_inline(); |
368 | | - } |
369 | | - } |
370 | | - |
371 | | - @Benchmark |
372 | | - public void iterator_dont_inline() { |
373 | | - for ( Iterator<Element> iter = this.listSpec.list.iterator(); iter.hasNext(); ) { |
374 | | - iter.next().manipulate_dont_inline(); |
375 | | - } |
| 340 | + @Benchmark |
| 341 | + public void forEach_inline() { |
| 342 | + this.listSpec.list.forEach(Element::manipulate_inline); |
| 343 | + } |
| 344 | + |
| 345 | + @Benchmark |
| 346 | + public void forEach_dont_inline() { |
| 347 | + this.listSpec.list.forEach(Element::manipulate_dont_inline); |
| 348 | + } |
| 349 | + |
| 350 | + @Benchmark |
| 351 | + public void enhancedFor_inline() { |
| 352 | + // Enhanced for-loop is just syntax sugar for an Iterator |
| 353 | + for (Element e : this.listSpec.list) { |
| 354 | + e.manipulate_inline(); |
376 | 355 | } |
377 | | - |
378 | | - |
379 | | - @Benchmark |
380 | | - public void cstyleFor_inline() { |
381 | | - for ( int i = 0; i < this.listSpec.list.size(); ++i ) { |
382 | | - this.listSpec.list.get(i).manipulate_inline(); |
383 | | - } |
| 356 | + } |
| 357 | + |
| 358 | + @Benchmark |
| 359 | + public void enhancedFor_dont_inline() { |
| 360 | + // Enhanced for-loop is just syntax sugar for an Iterator |
| 361 | + for (Element e : this.listSpec.list) { |
| 362 | + e.manipulate_dont_inline(); |
384 | 363 | } |
385 | | - |
386 | | - @Benchmark |
387 | | - public void cstyleFor_dont_inline() { |
388 | | - for ( int i = 0; i < this.listSpec.list.size(); ++i ) { |
389 | | - this.listSpec.list.get(i).manipulate_dont_inline(); |
390 | | - } |
| 364 | + } |
| 365 | + |
| 366 | + @Benchmark |
| 367 | + public void iterator_inline() { |
| 368 | + for (Iterator<Element> iter = this.listSpec.list.iterator(); iter.hasNext(); ) { |
| 369 | + iter.next().manipulate_inline(); |
391 | 370 | } |
392 | | - |
393 | | - @Benchmark |
394 | | - public void streams_inline() { |
395 | | - this.listSpec.list.stream().forEach(Element::manipulate_inline); |
| 371 | + } |
| 372 | + |
| 373 | + @Benchmark |
| 374 | + public void iterator_dont_inline() { |
| 375 | + for (Iterator<Element> iter = this.listSpec.list.iterator(); iter.hasNext(); ) { |
| 376 | + iter.next().manipulate_dont_inline(); |
396 | 377 | } |
397 | | - |
398 | | - @Benchmark |
399 | | - public void streams_dont_inline() { |
400 | | - this.listSpec.list.stream().forEach(Element::manipulate_dont_inline); |
| 378 | + } |
| 379 | + |
| 380 | + @Benchmark |
| 381 | + public void cstyleFor_inline() { |
| 382 | + for (int i = 0; i < this.listSpec.list.size(); ++i) { |
| 383 | + this.listSpec.list.get(i).manipulate_inline(); |
401 | 384 | } |
402 | | - |
403 | | - @Benchmark |
404 | | - public void parallelStreams_inline() { |
405 | | - listSpec.list.parallelStream().forEach(Element::manipulate_dont_inline); |
| 385 | + } |
| 386 | + |
| 387 | + @Benchmark |
| 388 | + public void cstyleFor_dont_inline() { |
| 389 | + for (int i = 0; i < this.listSpec.list.size(); ++i) { |
| 390 | + this.listSpec.list.get(i).manipulate_dont_inline(); |
406 | 391 | } |
| 392 | + } |
| 393 | + |
| 394 | + @Benchmark |
| 395 | + public void streams_inline() { |
| 396 | + this.listSpec.list.stream().forEach(Element::manipulate_inline); |
| 397 | + } |
| 398 | + |
| 399 | + @Benchmark |
| 400 | + public void streams_dont_inline() { |
| 401 | + this.listSpec.list.stream().forEach(Element::manipulate_dont_inline); |
| 402 | + } |
| 403 | + |
| 404 | + @Benchmark |
| 405 | + public void parallelStreams_inline() { |
| 406 | + listSpec.list.parallelStream().forEach(Element::manipulate_dont_inline); |
| 407 | + } |
407 | 408 |
|
408 | 409 | @Benchmark |
409 | 410 | public void parallelStreams_dont_inline() { |
|
0 commit comments