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 public class JniPerfBenchmark { 18 private static final String MSG = "ABCDE"; 19 perfJniEmptyCall()20 native void perfJniEmptyCall(); perfSOACall()21 native void perfSOACall(); perfSOAUncheckedCall()22 native void perfSOAUncheckedCall(); 23 timeFastJNI(int N)24 public void timeFastJNI(int N) { 25 // TODO: This might be an intrinsic. 26 for (long i = 0; i < N; i++) { 27 char c = MSG.charAt(2); 28 } 29 } 30 timeEmptyCall(int N)31 public void timeEmptyCall(int N) { 32 for (long i = 0; i < N; i++) { 33 perfJniEmptyCall(); 34 } 35 } 36 timeSOACall(int N)37 public void timeSOACall(int N) { 38 for (long i = 0; i < N; i++) { 39 perfSOACall(); 40 } 41 } 42 timeSOAUncheckedCall(int N)43 public void timeSOAUncheckedCall(int N) { 44 for (long i = 0; i < N; i++) { 45 perfSOAUncheckedCall(); 46 } 47 } 48 49 { 50 System.loadLibrary("artbenchmark"); 51 } 52 } 53