xref: /aosp_15_r20/art/benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker public class ScopedPrimitiveArrayBenchmark {
18*795d594fSAndroid Build Coastguard Worker   // Measure adds the first and last element of the array by using ScopedPrimitiveArray.
measureByteArray(int reps, byte[] arr)19*795d594fSAndroid Build Coastguard Worker   static native long measureByteArray(int reps, byte[] arr);
measureShortArray(int reps, short[] arr)20*795d594fSAndroid Build Coastguard Worker   static native long measureShortArray(int reps, short[] arr);
measureIntArray(int reps, int[] arr)21*795d594fSAndroid Build Coastguard Worker   static native long measureIntArray(int reps, int[] arr);
measureLongArray(int reps, long[] arr)22*795d594fSAndroid Build Coastguard Worker   static native long measureLongArray(int reps, long[] arr);
23*795d594fSAndroid Build Coastguard Worker 
24*795d594fSAndroid Build Coastguard Worker   static final int smallLength = 16;
25*795d594fSAndroid Build Coastguard Worker   static final int mediumLength = 256;
26*795d594fSAndroid Build Coastguard Worker   static final int largeLength = 8096;
27*795d594fSAndroid Build Coastguard Worker   static byte[] smallBytes = new byte[smallLength];
28*795d594fSAndroid Build Coastguard Worker   static byte[] mediumBytes = new byte[mediumLength];
29*795d594fSAndroid Build Coastguard Worker   static byte[] largeBytes = new byte[largeLength];
30*795d594fSAndroid Build Coastguard Worker   static short[] smallShorts = new short[smallLength];
31*795d594fSAndroid Build Coastguard Worker   static short[] mediumShorts = new short[mediumLength];
32*795d594fSAndroid Build Coastguard Worker   static short[] largeShorts = new short[largeLength];
33*795d594fSAndroid Build Coastguard Worker   static int[] smallInts = new int[smallLength];
34*795d594fSAndroid Build Coastguard Worker   static int[] mediumInts = new int[mediumLength];
35*795d594fSAndroid Build Coastguard Worker   static int[] largeInts = new int[largeLength];
36*795d594fSAndroid Build Coastguard Worker   static long[] smallLongs = new long[smallLength];
37*795d594fSAndroid Build Coastguard Worker   static long[] mediumLongs = new long[mediumLength];
38*795d594fSAndroid Build Coastguard Worker   static long[] largeLongs = new long[largeLength];
39*795d594fSAndroid Build Coastguard Worker 
timeSmallBytes(int reps)40*795d594fSAndroid Build Coastguard Worker   public void timeSmallBytes(int reps) {
41*795d594fSAndroid Build Coastguard Worker     measureByteArray(reps, smallBytes);
42*795d594fSAndroid Build Coastguard Worker   }
43*795d594fSAndroid Build Coastguard Worker 
timeMediumBytes(int reps)44*795d594fSAndroid Build Coastguard Worker   public void timeMediumBytes(int reps) {
45*795d594fSAndroid Build Coastguard Worker     measureByteArray(reps, mediumBytes);
46*795d594fSAndroid Build Coastguard Worker   }
47*795d594fSAndroid Build Coastguard Worker 
timeLargeBytes(int reps)48*795d594fSAndroid Build Coastguard Worker   public void timeLargeBytes(int reps) {
49*795d594fSAndroid Build Coastguard Worker     measureByteArray(reps, largeBytes);
50*795d594fSAndroid Build Coastguard Worker   }
51*795d594fSAndroid Build Coastguard Worker 
timeSmallShorts(int reps)52*795d594fSAndroid Build Coastguard Worker   public void timeSmallShorts(int reps) {
53*795d594fSAndroid Build Coastguard Worker     measureShortArray(reps, smallShorts);
54*795d594fSAndroid Build Coastguard Worker   }
55*795d594fSAndroid Build Coastguard Worker 
timeMediumShorts(int reps)56*795d594fSAndroid Build Coastguard Worker   public void timeMediumShorts(int reps) {
57*795d594fSAndroid Build Coastguard Worker     measureShortArray(reps, mediumShorts);
58*795d594fSAndroid Build Coastguard Worker   }
59*795d594fSAndroid Build Coastguard Worker 
timeLargeShorts(int reps)60*795d594fSAndroid Build Coastguard Worker   public void timeLargeShorts(int reps) {
61*795d594fSAndroid Build Coastguard Worker     measureShortArray(reps, largeShorts);
62*795d594fSAndroid Build Coastguard Worker   }
63*795d594fSAndroid Build Coastguard Worker 
timeSmallInts(int reps)64*795d594fSAndroid Build Coastguard Worker   public void timeSmallInts(int reps) {
65*795d594fSAndroid Build Coastguard Worker     measureIntArray(reps, smallInts);
66*795d594fSAndroid Build Coastguard Worker   }
67*795d594fSAndroid Build Coastguard Worker 
timeMediumInts(int reps)68*795d594fSAndroid Build Coastguard Worker   public void timeMediumInts(int reps) {
69*795d594fSAndroid Build Coastguard Worker     measureIntArray(reps, mediumInts);
70*795d594fSAndroid Build Coastguard Worker   }
71*795d594fSAndroid Build Coastguard Worker 
timeLargeInts(int reps)72*795d594fSAndroid Build Coastguard Worker   public void timeLargeInts(int reps) {
73*795d594fSAndroid Build Coastguard Worker     measureIntArray(reps, largeInts);
74*795d594fSAndroid Build Coastguard Worker   }
75*795d594fSAndroid Build Coastguard Worker 
timeSmallLongs(int reps)76*795d594fSAndroid Build Coastguard Worker   public void timeSmallLongs(int reps) {
77*795d594fSAndroid Build Coastguard Worker     measureLongArray(reps, smallLongs);
78*795d594fSAndroid Build Coastguard Worker   }
79*795d594fSAndroid Build Coastguard Worker 
timeMediumLongs(int reps)80*795d594fSAndroid Build Coastguard Worker   public void timeMediumLongs(int reps) {
81*795d594fSAndroid Build Coastguard Worker     measureLongArray(reps, mediumLongs);
82*795d594fSAndroid Build Coastguard Worker   }
83*795d594fSAndroid Build Coastguard Worker 
timeLargeLongs(int reps)84*795d594fSAndroid Build Coastguard Worker   public void timeLargeLongs(int reps) {
85*795d594fSAndroid Build Coastguard Worker     measureLongArray(reps, largeLongs);
86*795d594fSAndroid Build Coastguard Worker   }
87*795d594fSAndroid Build Coastguard Worker 
88*795d594fSAndroid Build Coastguard Worker   {
89*795d594fSAndroid Build Coastguard Worker     System.loadLibrary("artbenchmark");
90*795d594fSAndroid Build Coastguard Worker   }
91*795d594fSAndroid Build Coastguard Worker }
92