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 17 package benchmarks; 18 19 import com.google.caliper.Param; 20 import com.google.caliper.Runner; 21 import com.google.caliper.SimpleBenchmark; 22 23 import java.util.Arrays; 24 25 public class ArrayCopyBenchmark extends SimpleBenchmark { timeManualArrayCopy(int reps)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 time_System_arrayCopy(int reps)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 time_Arrays_copyOf(int reps)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 time_Arrays_copyOfRange(int reps)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 } 58