blob: 75ad243707e865f50a0c8a8988b0b2414fa6633c [file] [log] [blame]
Elliott Hughes97aba272013-02-13 16:21:51 -08001/*
2 * Copyright (C) 2010 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;
20import com.google.caliper.Runner;
21import com.google.caliper.SimpleBenchmark;
22
23import java.util.Arrays;
24
25public class ArrayCopyBenchmark extends SimpleBenchmark {
26 public void timeManualArrayCopy(int reps) {
27 char[] src = new char[8192];
28 for (int rep = 0; rep < reps; ++rep) {
29 char[] dst = new char[8192];
30 for (int i = 0; i < 8192; ++i) {
31 dst[i] = src[i];
32 }
33 }
34 }
35
36 public void time_System_arrayCopy(int reps) {
37 char[] src = new char[8192];
38 for (int rep = 0; rep < reps; ++rep) {
39 char[] dst = new char[8192];
40 System.arraycopy(src, 0, dst, 0, 8192);
41 }
42 }
43
44 public void time_Arrays_copyOf(int reps) {
45 char[] src = new char[8192];
46 for (int rep = 0; rep < reps; ++rep) {
47 char[] dst = Arrays.copyOf(src, 8192);
48 }
49 }
50
51 public void time_Arrays_copyOfRange(int reps) {
52 char[] src = new char[8192];
53 for (int rep = 0; rep < reps; ++rep) {
54 char[] dst = Arrays.copyOfRange(src, 0, 8192);
55 }
56 }
57}