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 | |
| 17 | #include "jni.h" |
Steven Moreland | e431e27 | 2017-07-18 16:53:49 -0700 | [diff] [blame] | 18 | #include "nativehelper/ScopedPrimitiveArray.h" |
Mathieu Chartier | 563e984 | 2015-09-12 16:55:26 -0700 | [diff] [blame] | 19 | |
| 20 | extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureByteArray( |
| 21 | JNIEnv* env, jclass, int reps, jbyteArray arr) { |
| 22 | jlong ret = 0; |
| 23 | for (jint i = 0; i < reps; ++i) { |
| 24 | ScopedByteArrayRO sc(env, arr); |
| 25 | ret += sc[0] + sc[sc.size() - 1]; |
| 26 | } |
| 27 | return ret; |
| 28 | } |
| 29 | |
| 30 | extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureShortArray( |
| 31 | JNIEnv* env, jclass, int reps, jshortArray arr) { |
| 32 | jlong ret = 0; |
| 33 | for (jint i = 0; i < reps; ++i) { |
| 34 | ScopedShortArrayRO sc(env, arr); |
| 35 | ret += sc[0] + sc[sc.size() - 1]; |
| 36 | } |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureIntArray( |
| 41 | JNIEnv* env, jclass, int reps, jintArray arr) { |
| 42 | jlong ret = 0; |
| 43 | for (jint i = 0; i < reps; ++i) { |
| 44 | ScopedIntArrayRO sc(env, arr); |
| 45 | ret += sc[0] + sc[sc.size() - 1]; |
| 46 | } |
| 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureLongArray( |
| 51 | JNIEnv* env, jclass, int reps, jlongArray arr) { |
| 52 | jlong ret = 0; |
| 53 | for (jint i = 0; i < reps; ++i) { |
| 54 | ScopedLongArrayRO sc(env, arr); |
| 55 | ret += sc[0] + sc[sc.size() - 1]; |
| 56 | } |
| 57 | return ret; |
| 58 | } |