Mathieu Chartier | 563e984 | 2015-09-12 16:55:26 -0700 | [diff] [blame] | 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 | |
bowen_lai | 27cdee6 | 2016-03-24 19:15:38 +0800 | [diff] [blame] | 17 | public class JniPerfBenchmark { |
Mathieu Chartier | 563e984 | 2015-09-12 16:55:26 -0700 | [diff] [blame] | 18 | private static final String MSG = "ABCDE"; |
| 19 | |
| 20 | native void perfJniEmptyCall(); |
| 21 | native void perfSOACall(); |
| 22 | native void perfSOAUncheckedCall(); |
| 23 | |
| 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 | |
| 31 | public void timeEmptyCall(int N) { |
| 32 | for (long i = 0; i < N; i++) { |
| 33 | perfJniEmptyCall(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public void timeSOACall(int N) { |
| 38 | for (long i = 0; i < N; i++) { |
| 39 | perfSOACall(); |
| 40 | } |
| 41 | } |
| 42 | |
| 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 | } |