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"
18 #include "nativehelper/scoped_primitive_array.h"
19 
Java_ScopedPrimitiveArrayBenchmark_measureByteArray(JNIEnv * env,jclass,int reps,jbyteArray arr)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 
Java_ScopedPrimitiveArrayBenchmark_measureShortArray(JNIEnv * env,jclass,int reps,jshortArray arr)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 
Java_ScopedPrimitiveArrayBenchmark_measureIntArray(JNIEnv * env,jclass,int reps,jintArray arr)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 
Java_ScopedPrimitiveArrayBenchmark_measureLongArray(JNIEnv * env,jclass,int reps,jlongArray arr)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 }
59