|
1 /* |
|
2 * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package org.openjdk.bench.vm.lambda.chain; |
|
24 import org.openjdk.jmh.annotations.Benchmark; |
|
25 import org.openjdk.jmh.annotations.BenchmarkMode; |
|
26 import org.openjdk.jmh.annotations.Mode; |
|
27 import org.openjdk.jmh.annotations.OperationsPerInvocation; |
|
28 import org.openjdk.jmh.annotations.OutputTimeUnit; |
|
29 import org.openjdk.jmh.annotations.Scope; |
|
30 import org.openjdk.jmh.annotations.Setup; |
|
31 import org.openjdk.jmh.annotations.State; |
|
32 import org.openjdk.jmh.infra.Blackhole; |
|
33 |
|
34 import java.util.concurrent.TimeUnit; |
|
35 |
|
36 /** |
|
37 * Chain of (capture + invocation) microbenchmark. |
|
38 */ |
|
39 @State(Scope.Benchmark) |
|
40 @BenchmarkMode(Mode.AverageTime) |
|
41 @OutputTimeUnit(TimeUnit.NANOSECONDS) |
|
42 public class ChainMrefBound extends ChainBase { |
|
43 |
|
44 public Level start1; |
|
45 public Level start2; |
|
46 public Level start4; |
|
47 public Level start8; |
|
48 |
|
49 @Setup |
|
50 public void init() { |
|
51 start1 = get1(); |
|
52 start2 = get2(); |
|
53 start4 = get4(); |
|
54 start8 = get8(); |
|
55 } |
|
56 |
|
57 @Benchmark |
|
58 @OperationsPerInvocation(1) |
|
59 public void call1(Blackhole bh) { |
|
60 process(bh, start1); |
|
61 } |
|
62 |
|
63 @Benchmark |
|
64 @OperationsPerInvocation(2) |
|
65 public void call2(Blackhole bh) { |
|
66 process(bh, start2); |
|
67 } |
|
68 |
|
69 @Benchmark |
|
70 @OperationsPerInvocation(4) |
|
71 public void call4(Blackhole bh) { |
|
72 process(bh, start4); |
|
73 } |
|
74 |
|
75 @Benchmark |
|
76 @OperationsPerInvocation(8) |
|
77 public void call8(Blackhole bh) { |
|
78 process(bh, start8); |
|
79 } |
|
80 |
|
81 public TopLevel get0() { |
|
82 return () -> "GOT: "; |
|
83 } |
|
84 |
|
85 public Level get1() { |
|
86 return this::get0; |
|
87 } |
|
88 |
|
89 public Level get2() { |
|
90 return this::get1; |
|
91 } |
|
92 |
|
93 public Level get3() { |
|
94 return this::get2; |
|
95 } |
|
96 |
|
97 public Level get4() { |
|
98 return this::get3; |
|
99 } |
|
100 |
|
101 public Level get5() { |
|
102 return this::get4; |
|
103 } |
|
104 |
|
105 public Level get6() { |
|
106 return this::get5; |
|
107 } |
|
108 |
|
109 public Level get7() { |
|
110 return this::get6; |
|
111 } |
|
112 |
|
113 public Level get8() { |
|
114 return this::get7; |
|
115 } |
|
116 |
|
117 } |