1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import com.google.caliper.SimpleBenchmark; 18 19 public class JniPerfBenchmark extends SimpleBenchmark { 20 private static final String MSG = "ABCDE"; 21 22 native void perfJniEmptyCall(); 23 native void perfSOACall(); 24 native void perfSOAUncheckedCall(); 25 26 public void timeFastJNI(int N) { 27 // TODO: This might be an intrinsic. 28 for (long i = 0; i < N; i++) { 29 char c = MSG.charAt(2); 30 } 31 } 32 33 public void timeEmptyCall(int N) { 34 for (long i = 0; i < N; i++) { 35 perfJniEmptyCall(); 36 } 37 } 38 39 public void timeSOACall(int N) { 40 for (long i = 0; i < N; i++) { 41 perfSOACall(); 42 } 43 } 44 45 public void timeSOAUncheckedCall(int N) { 46 for (long i = 0; i < N; i++) { 47 perfSOAUncheckedCall(); 48 } 49 } 50 51 { 52 System.loadLibrary("artbenchmark"); 53 } 54 } 55