let utils = require('./../utils'); let n = 20000; let arr = utils.getRandomArray(n, 0, n); // 生成随机数数组 let arr2 = utils.copyArray(arr); let arr3 = utils.copyArray(arr);
let time1 = utils.testSort(arr, bubbleSort); let time2 = utils.testSort(arr2, bubbleSort2); let time3 = utils.testSort(arr3, bubbleSort3);
console.log('bubble sort: ', time1); // bubble sort: 2.522000 s console.log('bubble sort2: ', time2); // bubble sort2: 2.479000 s console.log('bubble sort3: ', time3); // bubble sort3: 2.436000 s
// 测试 let utils = require('./../utils'); let n = 50000; let arr = utils.getNearlyArray(n, 1); // 生成一个函数,[1,2,3,4,5...49999],随意将其中的两个数进行交换 let arr2 = utils.copyArray(arr); let arr3 = utils.copyArray(arr);
let time1 = utils.testSort(arr, bubbleSort); let time2 = utils.testSort(arr2, bubbleSort2); let time3 = utils.testSort(arr3, bubbleSort3);
console.log('bubble sort: ', time1); // bubble sort: 5.000000 s console.log('bubble sort2: ', time2); // bubble sort2: 2.673000 s console.log('bubble sort3: ', time3); // bubble sort3: 2.497000 s
let n = 80000; // let arr = utils.getRandomArray(n, 0, n); let arr = utils.getNearlyArray(n, 1); // 近乎有序的数组 let arr2 = utils.copyArray(arr); let arr3 = utils.copyArray(arr); let arr4 = utils.copyArray(arr);
let time1 = utils.testSort(arr, Bubble.bubbleSort3); let time2 = utils.testSort(arr2, Insert.insertSort2); let time3 = utils.testSort(arr3, Select.selectionSort); let time4 = utils.testSort(arr4, Shell.shellSort);
// 当排序近乎有序的数组时,80000的数据量 console.log('bubble sort: ', time1); // bubble sort: 2.604000 s console.log('insert sort: ', time2); // insert sort: 0.002000 s console.log('select sort: ', time3); // select sort: 10.727000 s console.log('shell sort: ', time4); // shell sort: 0.039000 s
// 当排序随机无序的数组时,依旧是80000的数据量 console.log('bubble sort: ', time1); // bubble sort: 42.850000 s console.log('insert sort: ', time2); // insert sort: 1.998000 s console.log('select sort: ', time3); // select sort: 11.893000 s console.log('shell sort: ', time4); // shell sort: 0.107000 s