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 ScopedPrimitiveArrayBenchmark {
18   // Measure adds the first and last element of the array by using ScopedPrimitiveArray.
measureByteArray(int reps, byte[] arr)19   static native long measureByteArray(int reps, byte[] arr);
measureShortArray(int reps, short[] arr)20   static native long measureShortArray(int reps, short[] arr);
measureIntArray(int reps, int[] arr)21   static native long measureIntArray(int reps, int[] arr);
measureLongArray(int reps, long[] arr)22   static native long measureLongArray(int reps, long[] arr);
23 
24   static final int smallLength = 16;
25   static final int mediumLength = 256;
26   static final int largeLength = 8096;
27   static byte[] smallBytes = new byte[smallLength];
28   static byte[] mediumBytes = new byte[mediumLength];
29   static byte[] largeBytes = new byte[largeLength];
30   static short[] smallShorts = new short[smallLength];
31   static short[] mediumShorts = new short[mediumLength];
32   static short[] largeShorts = new short[largeLength];
33   static int[] smallInts = new int[smallLength];
34   static int[] mediumInts = new int[mediumLength];
35   static int[] largeInts = new int[largeLength];
36   static long[] smallLongs = new long[smallLength];
37   static long[] mediumLongs = new long[mediumLength];
38   static long[] largeLongs = new long[largeLength];
39 
timeSmallBytes(int reps)40   public void timeSmallBytes(int reps) {
41     measureByteArray(reps, smallBytes);
42   }
43 
timeMediumBytes(int reps)44   public void timeMediumBytes(int reps) {
45     measureByteArray(reps, mediumBytes);
46   }
47 
timeLargeBytes(int reps)48   public void timeLargeBytes(int reps) {
49     measureByteArray(reps, largeBytes);
50   }
51 
timeSmallShorts(int reps)52   public void timeSmallShorts(int reps) {
53     measureShortArray(reps, smallShorts);
54   }
55 
timeMediumShorts(int reps)56   public void timeMediumShorts(int reps) {
57     measureShortArray(reps, mediumShorts);
58   }
59 
timeLargeShorts(int reps)60   public void timeLargeShorts(int reps) {
61     measureShortArray(reps, largeShorts);
62   }
63 
timeSmallInts(int reps)64   public void timeSmallInts(int reps) {
65     measureIntArray(reps, smallInts);
66   }
67 
timeMediumInts(int reps)68   public void timeMediumInts(int reps) {
69     measureIntArray(reps, mediumInts);
70   }
71 
timeLargeInts(int reps)72   public void timeLargeInts(int reps) {
73     measureIntArray(reps, largeInts);
74   }
75 
timeSmallLongs(int reps)76   public void timeSmallLongs(int reps) {
77     measureLongArray(reps, smallLongs);
78   }
79 
timeMediumLongs(int reps)80   public void timeMediumLongs(int reps) {
81     measureLongArray(reps, mediumLongs);
82   }
83 
timeLargeLongs(int reps)84   public void timeLargeLongs(int reps) {
85     measureLongArray(reps, largeLongs);
86   }
87 
88   {
89     System.loadLibrary("artbenchmark");
90   }
91 }
92