1/*
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 java.util.Arrays;
20
21public class ArrayCopyBenchmark {
22    public void timeManualArrayCopy(int reps) {
23        char[] src = new char[8192];
24        for (int rep = 0; rep < reps; ++rep) {
25            char[] dst = new char[8192];
26            for (int i = 0; i < 8192; ++i) {
27                dst[i] = src[i];
28            }
29        }
30    }
31
32    public void time_System_arrayCopy(int reps) {
33        char[] src = new char[8192];
34        for (int rep = 0; rep < reps; ++rep) {
35            char[] dst = new char[8192];
36            System.arraycopy(src, 0, dst, 0, 8192);
37        }
38    }
39
40    public void time_Arrays_copyOf(int reps) {
41        char[] src = new char[8192];
42        for (int rep = 0; rep < reps; ++rep) {
43            char[] dst = Arrays.copyOf(src, 8192);
44        }
45    }
46
47    public void time_Arrays_copyOfRange(int reps) {
48        char[] src = new char[8192];
49        for (int rep = 0; rep < reps; ++rep) {
50            char[] dst = Arrays.copyOfRange(src, 0, 8192);
51        }
52    }
53}
54