Skip to content

Instantly share code, notes, and snippets.

@Vogel612
Created September 27, 2015 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vogel612/814e851a6c2de1ced765 to your computer and use it in GitHub Desktop.
Save Vogel612/814e851a6c2de1ced765 to your computer and use it in GitHub Desktop.
MicroBench run comparing System.arraycopy with calling .clone on an array
Task Array Copying Comparisons -> Copying 100 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 23,3920
Fastest : 0,8380 Slowest : 51323,3390
95Pctile : 2,2350 99Pctile : 3,8410
TimeBlock : 15,103 1,985 24,140 2,550 6,178 53,078 19,353 71,661 14,326 25,554
Histogram : 3527 6359 78 12 5 1 2 0 1 3 1 0 3 3 2 3
Task Array Copying Comparisons -> Cloning 100 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 18,1080
Fastest : 0,8380 Slowest : 80175,0720
95Pctile : 2,1650 99Pctile : 4,7490
TimeBlock : 1,897 2,136 1,495 81,781 3,189 1,250 1,277 1,175 83,622 3,265
Histogram : 6642 3148 176 21 3 3 1 0 0 0 1 1 1 0 0 2 1
Task Array Copying Comparisons -> Copying 300 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 24,0260
Fastest : 0,9080 Slowest : 58185,5310
95Pctile : 2,7940 99Pctile : 4,1200
TimeBlock : 27,701 12,552 1,544 82,655 10,851 1,555 2,455 63,472 35,069 2,415
Histogram : 3432 6377 147 13 3 6 2 2 4 2 2 1 2 2 3 2
Task Array Copying Comparisons -> Cloning 300 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 27,2090
Fastest : 0,9080 Slowest : 56840,4020
95Pctile : 3,4220 99Pctile : 5,3080
TimeBlock : 25,166 2,718 33,043 58,922 1,822 15,088 18,550 92,769 1,856 22,159
Histogram : 2487 7050 419 22 4 3 1 0 0 0 0 2 1 5 3 3
Task Array Copying Comparisons -> Copying 500 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 36,6730
Fastest : 0,9080 Slowest : 51877,8320
95Pctile : 4,3310 99Pctile : 6,4950
TimeBlock : 25,055 18,948 63,079 69,276 12,717 103,293 14,512 20,610 25,309 13,936
Histogram : 709 8151 1062 33 7 8 2 2 1 1 2 3 3 11 2 3
Task Array Copying Comparisons -> Cloning 500 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 35,4540
Fastest : 0,9080 Slowest : 78640,5950
95Pctile : 3,8420 99Pctile : 5,1680
TimeBlock : 33,438 36,611 82,758 2,062 2,263 27,903 3,671 100,427 30,849 34,560
Histogram : 423 8842 683 22 5 4 2 1 0 0 2 1 1 6 6 1 1
Task Array Copying Comparisons -> Copying 1000 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 49,3280
Fastest : 1,2570 Slowest : 67943,3960
95Pctile : 5,7970 99Pctile : 7,6130
TimeBlock : 42,182 123,448 43,062 17,997 128,847 3,993 65,774 16,066 19,459 32,460
Histogram : 355 8426 1156 25 5 2 0 0 2 4 2 4 5 6 6 2
Task Array Copying Comparisons -> Cloning 1000 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 51,5940
Fastest : 1,2570 Slowest : 57723,4440
95Pctile : 5,9360 99Pctile : 9,1500
TimeBlock : 60,024 101,436 66,544 41,199 93,536 31,879 42,019 20,345 35,645 23,321
Histogram : 761 7503 1646 43 5 2 1 3 3 3 6 0 5 14 2 3
Task Array Copying Comparisons -> Copying 1200 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 42,8640
Fastest : 1,7460 Slowest : 47815,6930
95Pctile : 6,7050 99Pctile : 10,2670
TimeBlock : 13,586 89,576 63,548 102,621 26,821 20,289 23,625 43,915 20,189 24,470
Histogram : 1511 8062 370 22 6 2 1 0 4 0 1 2 9 7 3
Task Array Copying Comparisons -> Cloning 1200 elements: (Unit: MICROSECONDS)
Count : 10000 Average : 42,1840
Fastest : 1,4670 Slowest : 76831,4200
95Pctile : 6,7050 99Pctile : 10,9650
TimeBlock : 117,113 61,121 33,216 89,382 7,355 39,713 9,671 5,023 29,442 29,806
Histogram : 356 8605 958 40 13 4 1 0 3 1 2 3 3 4 6 1
import java.util.Random;
import net.tuis.ubench.UBench;
import net.tuis.ubench.UMode;
/**
* Created by vogel612 on 27.09.15.
*/
public class Tests {
private static int[] LIMITS = {100, 300, 500, 1000, 1200};
private static final Random rng = new Random();
public static void main (String[]args) {
UBench bench = new UBench("Array Copying Comparisons");
for (int limit : LIMITS) {
final int[] sample = new int[limit];
fillArray(sample);
bench.addTask(String.format("Copying %d elements", limit),
() -> {
final int[] result = new int[sample.length];
System.arraycopy(sample, 0, result, 0, sample.length);
return result;
});
bench.addTask(String.format("Cloning %d elements", limit),
() -> sample.clone());
}
bench.press(UMode.PARALLEL, 10000).report();
}
private static void fillArray(int[] sample) {
for (int i = 0; i < sample.length; i++) {
sample[i] = rng.nextInt(sample.length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment