62,623
社区成员
发帖
与我相关
我的任务
分享package Collections;
import java.util.Arrays;
/**
* Created by piqiu on 1/16/16.
*/
public class CollectionsTest {
public static void main(String[] args) {
int source[] = new int[100000000];
Arrays.fill(source, 250);
int destinate[] = new int[100000000];
// useForEach(source, 0, destinate, 0, 100000000); // useForEach spend: 63 millSeconds
useMemocpy(source, 0, destinate, 0, 100000000); // useMemocpy spend: 76 millSeconds
}
private static void useForEach(int[] source, int startSourceIndex, int[] destinate, int startDesIndex, int length) {
long startMillSeconds = System.currentTimeMillis();
int desIndex = startDesIndex;
for (int i = startSourceIndex; i < length; i++) {
destinate[desIndex] = source[startSourceIndex];
desIndex++;
}
long endMillSeconds = System.currentTimeMillis();
System.out.println("useForEach spend: " + (endMillSeconds - startMillSeconds) + " millSeconds");
}
private static void useMemocpy(int[] source, int startSourceIndex, int[] destinate, int startDesIndex, int length) {
long startMillSeconds = System.currentTimeMillis();
System.arraycopy(source, startSourceIndex, destinate, startDesIndex, length);
long endMillSeconds = System.currentTimeMillis();
System.out.println("useMemocpy spend: " + (endMillSeconds - startMillSeconds) + " millSeconds");
}
}