blob: 000b497589efa5682f291ea2ed1ec82cd8addd8a [file] [log] [blame]
Alan Viverette3da604b2020-06-10 18:34:39 +00001/*
2 * Copyright (C) 2013 Google Inc.
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
17package benchmarks;
18
19import com.google.caliper.Param;
20
21public class SystemArrayCopyBenchmark {
22 @Param({"2", "4", "8", "16", "32", "64", "128", "256", "512", "1024",
23 "2048", "4096", "8192", "16384", "32768", "65536", "131072", "262144"})
24 int arrayLength;
25
26 // Provides benchmarking for different types of arrays using the arraycopy function.
27
28 public void timeSystemCharArrayCopy(int reps) {
29 final int len = arrayLength;
30 char[] src = new char[len];
31 char[] dst = new char[len];
32 for (int rep = 0; rep < reps; ++rep) {
33 System.arraycopy(src, 0, dst, 0, len);
34 }
35 }
36
37 public void timeSystemByteArrayCopy(int reps) {
38 final int len = arrayLength;
39 byte[] src = new byte[len];
40 byte[] dst = new byte[len];
41 for (int rep = 0; rep < reps; ++rep) {
42 System.arraycopy(src, 0, dst, 0, len);
43 }
44 }
45
46 public void timeSystemShortArrayCopy(int reps) {
47 final int len = arrayLength;
48 short[] src = new short[len];
49 short[] dst = new short[len];
50 for (int rep = 0; rep < reps; ++rep) {
51 System.arraycopy(src, 0, dst, 0, len);
52 }
53 }
54
55 public void timeSystemIntArrayCopy(int reps) {
56 final int len = arrayLength;
57 int[] src = new int[len];
58 int[] dst = new int[len];
59 for (int rep = 0; rep < reps; ++rep) {
60 System.arraycopy(src, 0, dst, 0, len);
61 }
62 }
63
64 public void timeSystemLongArrayCopy(int reps) {
65 final int len = arrayLength;
66 long[] src = new long[len];
67 long[] dst = new long[len];
68 for (int rep = 0; rep < reps; ++rep) {
69 System.arraycopy(src, 0, dst, 0, len);
70 }
71 }
72
73 public void timeSystemFloatArrayCopy(int reps) {
74 final int len = arrayLength;
75 float[] src = new float[len];
76 float[] dst = new float[len];
77 for (int rep = 0; rep < reps; ++rep) {
78 System.arraycopy(src, 0, dst, 0, len);
79 }
80 }
81
82 public void timeSystemDoubleArrayCopy(int reps) {
83 final int len = arrayLength;
84 double[] src = new double[len];
85 double[] dst = new double[len];
86 for (int rep = 0; rep < reps; ++rep) {
87 System.arraycopy(src, 0, dst, 0, len);
88 }
89 }
90
91 public void timeSystemBooleanArrayCopy(int reps) {
92 final int len = arrayLength;
93 boolean[] src = new boolean[len];
94 boolean[] dst = new boolean[len];
95 for (int rep = 0; rep < reps; ++rep) {
96 System.arraycopy(src, 0, dst, 0, len);
97 }
98 }
99}