I ran your code on my system: there's virtually no difference between them. Both clock in at about 30 milliseconds. My test is on OpenJDK 7.
To confirm I also ran it through Caliper, and used a larger array to emphasize the actual copying performance:
public class Performance extends SimpleBenchmark { final int[] source = new int[1000]; public int timeClone(int reps) { int sum = 0; for (int i = reps; i > 0; i--) sum += source.clone().length; return sum; } public int timeCopyOf(int reps) { int sum = 0; for (int i = reps; i > 0; i--) sum += Arrays.copyOf(source,source.length).length; return sum; } public static void main(String... args) { Runner.main(Performance.class, args); } }
Result:
0% Scenario{vm=java, trial=0, benchmark=Clone} 2141.70 ns; σ=5416.80 ns @ 10 trials 50% Scenario{vm=java, trial=0, benchmark=CopyOf} 2168.38 ns; σ=1545.85 ns @ 10 trials benchmark us linear runtime Clone 2.14 ============================= CopyOf 2.17 ============================== vm: java trial: 0
Per request, here it is with array size 10:
0% Scenario{vm=java, trial=0, benchmark=Clone} 30.07 ns; σ=2.12 ns @ 10 trials 50% Scenario{vm=java, trial=0, benchmark=CopyOf} 29.34 ns; σ=161.38 ns @ 10 trials benchmark ns linear runtime Clone 30.1 ============================== CopyOf 29.3 =============================
cloneis overloaded (because it must handle both pointer and scalar arrays), and, in the standard Sun/Oracle implementation, likely under-optimized. I've worked on implementations ofclonethat would most certainly do much better.