summaryrefslogtreecommitdiff
path: root/benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-09-12 16:55:26 -0700
committerMathieu Chartier <mathieuc@google.com>2015-09-14 13:45:53 -0700
commit563e9846711aa1830bc7a34499204091032349fb (patch)
treecd7974c696430f703d65c2e82ba347df900a4aaf /benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java
parentb09f33381174843214de40533366e162a0c6d768 (diff)
Convert ART benchmarks into caliper benchmarks
Move the ART benchmarks into the benchmarks directory and make them caliper friendly. To run you need to build libartbenchmark.so and sync it then use vogar --benchmark. Bug: 24055147 Change-Id: Idc9caf8dc8022190d737840ba0eb9e356f9872cb
Diffstat (limited to 'benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java')
-rw-r--r--benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java b/benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java
new file mode 100644
index 0000000000..be276fe48c
--- /dev/null
+++ b/benchmark/scoped-primitive-array/src/ScopedPrimitiveArrayBenchmark.java
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+import com.google.caliper.SimpleBenchmark;
+
+public class ScopedPrimitiveArrayBenchmark extends SimpleBenchmark {
+ // 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");
+ }
+}