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.capture; 24 25 import org.openjdk.jmh.annotations.Benchmark; 26 import org.openjdk.jmh.annotations.BenchmarkMode; 27 import org.openjdk.jmh.annotations.Mode; 28 import org.openjdk.jmh.annotations.OutputTimeUnit; 29 30 import java.util.concurrent.TimeUnit; 31 32 /** 33 * evaluates method reference capture 34 * 35 * @author Sergey Kuksenko (sergey.kuksenko@oracle.com) 36 */ 37 @BenchmarkMode(Mode.AverageTime) 38 @OutputTimeUnit(TimeUnit.NANOSECONDS) 39 public class CaptureMR { 40 41 public static class Mock0 { 42 public Mock0() { 43 } 44 } 45 46 public static Object method_static() { 47 return "42"; 48 } 49 50 public Object method_instance() { 51 return "42"; 52 } 53 54 @Benchmark() 55 public FunctionalInterface0 mref_static0(){ 56 return CaptureMR::method_static; 57 } 58 59 @Benchmark() 60 public FunctionalInterface0 mref_bound0(){ 61 return this::method_instance; 62 } 63 64 @Benchmark() 65 public FunctionalInterface0 mref_constructor0(){ 66 return Mock0::new; 67 } 68 69 70 //--------------------------- 71 72 public static class Mock1 { 73 private Object oo; 74 public Mock1(Object o) { 75 oo = o; 76 } 77 } 78 79 public static Object method_static(Object bar) { 80 return "42" + bar; 81 } 82 83 public Object method_instance(Object bar) { 84 return "42" + bar; 85 } 86 87 @Benchmark() 88 public FunctionalInterface1 mref_static1(){ 89 return CaptureMR::method_static; 90 } 91 92 @Benchmark() 93 public FunctionalInterface1 mref_bound1(){ 94 return this::method_instance; 95 } 96 97 @Benchmark() 98 public FunctionalInterface1 mref_constructor1(){ 99 return Mock1::new; 100 } 101 102 }