summaryrefslogtreecommitdiff
path: root/benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java
blob: 0ad9c369505ff2b32916045002c12c4dc0b9a043 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class ScopedPrimitiveArrayBenchmark {
  // Measure adds the first and last element of the array by using ScopedPrimitiveArray.
  static native long measureByteArray(int reps, byte[] arr);
  static native long measureShortArray(int reps, short[] arr);
  static native long measureIntArray(int reps, int[] arr);
  static native long measureLongArray(int reps, long[] arr);

  static final int smallLength = 16;
  static final int mediumLength = 256;
  static final int largeLength = 8096;
  static byte[] smallBytes = new byte[smallLength];
  static byte[] mediumBytes = new byte[mediumLength];
  static byte[] largeBytes = new byte[largeLength];
  static short[] smallShorts = new short[smallLength];
  static short[] mediumShorts = new short[mediumLength];
  static short[] largeShorts = new short[largeLength];
  static int[] smallInts = new int[smallLength];
  static int[] mediumInts = new int[mediumLength];
  static int[] largeInts = new int[largeLength];
  static long[] smallLongs = new long[smallLength];
  static long[] mediumLongs = new long[mediumLength];
  static long[] largeLongs = new long[largeLength];

  public void timeSmallBytes(int reps) {
    measureByteArray(reps, smallBytes);
  }

  public void timeMediumBytes(int reps) {
    measureByteArray(reps, mediumBytes);
  }

  public void timeLargeBytes(int reps) {
    measureByteArray(reps, largeBytes);
  }

  public void timeSmallShorts(int reps) {
    measureShortArray(reps, smallShorts);
  }

  public void timeMediumShorts(int reps) {
    measureShortArray(reps, mediumShorts);
  }

  public void timeLargeShorts(int reps) {
    measureShortArray(reps, largeShorts);
  }

  public void timeSmallInts(int reps) {
    measureIntArray(reps, smallInts);
  }

  public void timeMediumInts(int reps) {
    measureIntArray(reps, mediumInts);
  }

  public void timeLargeInts(int reps) {
    measureIntArray(reps, largeInts);
  }

  public void timeSmallLongs(int reps) {
    measureLongArray(reps, smallLongs);
  }

  public void timeMediumLongs(int reps) {
    measureLongArray(reps, mediumLongs);
  }

  public void timeLargeLongs(int reps) {
    measureLongArray(reps, largeLongs);
  }

  {
    System.loadLibrary("artbenchmark");
  }
}