File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
src/java.base/share/classes/java/util
test/micro/org/openjdk/bench/java/util Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -5182,6 +5182,16 @@ public E get(int index) {
51825182 return element ;
51835183 }
51845184
5185+ @ Override
5186+ public void forEach (Consumer <? super E > action ) {
5187+ Objects .requireNonNull (action );
5188+ int n = this .n ;
5189+ E element = this .element ;
5190+ for (int i = 0 ; i < n ; i ++) {
5191+ action .accept (element );
5192+ }
5193+ }
5194+
51855195 public Object [] toArray () {
51865196 final Object [] a = new Object [n ];
51875197 if (element != null )
Original file line number Diff line number Diff line change 1+ package micro .org .openjdk .bench .java .util ;
2+
3+ import org .openjdk .jmh .annotations .*;
4+ import org .openjdk .jmh .infra .Blackhole ;
5+
6+ import java .util .*;
7+ import java .util .concurrent .TimeUnit ;
8+
9+ /**
10+ * @see <a href="https://bugs.openjdk.java.net/browse/JDK-8274715">JDK-8274715</a>
11+ */
12+ @ Fork (value = 3 )
13+ @ State (Scope .Thread )
14+ @ BenchmarkMode (Mode .AverageTime )
15+ @ OutputTimeUnit (TimeUnit .NANOSECONDS )
16+ @ Warmup (iterations = 5 , time = 1 , timeUnit = TimeUnit .SECONDS )
17+ @ Measurement (iterations = 5 , time = 2 , timeUnit = TimeUnit .SECONDS )
18+ public class NCopiesBenchmarks {
19+ @ Param ({"10" , "50" , "100" })
20+ int size ;
21+
22+ private List <Object > list ;
23+
24+ @ Setup
25+ public void prepare () {
26+ list = Collections .nCopies (size , new Object ());
27+ }
28+
29+ @ Benchmark
30+ public void forEach (Blackhole bh ) {
31+ list .forEach (bh ::consume );
32+ }
33+
34+ }
You can’t perform that action at this time.
0 commit comments