add mergesort time test

This commit is contained in:
ehlxr 2021-07-03 13:11:51 +08:00
parent dccb21493b
commit 0b5acb84ab
2 changed files with 10 additions and 4 deletions

View File

@ -37,9 +37,17 @@ import java.util.Arrays;
*/ */
public class MergeSort { public class MergeSort {
public static void main(String[] args) { public static void main(String[] args) {
int[] arr = {4, 9, 1, 8, 6, 2}; int[] arr = new int[800_000];
for (int i = 0; i < 800_000; i++) {
arr[i] = (int) (Math.random() * 80_000_000); //生成一个[0, 8000000)
}
long startTime = System.currentTimeMillis();
sort(arr);
System.out.printf("排序花费时间 %dms.", System.currentTimeMillis() - startTime);
// int[] arr = {4, 9, 1, 8, 6, 2};
// merge(new int[]{1, 4, 9}, new int[]{2, 6, 8}); // merge(new int[]{1, 4, 9}, new int[]{2, 6, 8});
System.out.println(Arrays.toString(sort(arr))); // System.out.println(Arrays.toString(sort(arr)));
} }
/** /**

View File

@ -45,8 +45,6 @@ public class QuickSort {
for (int i = 0; i < 800_000; i++) { for (int i = 0; i < 800_000; i++) {
arr[i] = (int) (Math.random() * 80_000_000); //生成一个[0, 8000000) arr[i] = (int) (Math.random() * 80_000_000); //生成一个[0, 8000000)
} }
// int[] arr = {4, 9, 1, 8, 6, 2};
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
sort(arr, 0, arr.length - 1); sort(arr, 0, arr.length - 1);
System.out.printf("排序花费时间 %dms.", System.currentTimeMillis() - startTime); System.out.printf("排序花费时间 %dms.", System.currentTimeMillis() - startTime);