-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
常用排序算法汇总 #23
Comments
测试结果1(100000个元素。注意,多次执行测试结果会不一样,但能看出大概性能)// Prepare
var ARRAY_LENGTH = 100000;
var MAX_VALUE = ARRAY_LENGTH * 10;
var arr = new Array(ARRAY_LENGTH).fill(0).map(x => Math.floor(Math.random() * MAX_VALUE));
// Test quick sort
console.time('quick sort');
quickSort(arr);
console.timeEnd('quick sort');
// Test bulle sort
console.time('bulle sort');
bubbleSort(arr);
console.timeEnd('bulle sort');
// Test select sort
console.time('select sort');
bubbleSort(arr);
console.timeEnd('select sort');
// Test insertion sort
console.time('insertion sort');
insertionSort(arr);
console.timeEnd('insertion sort');
// Test merge sort
console.time('merge sort');
mergeSort(arr);
console.timeEnd('merge sort');
VM31:137 quick sort: 103.68115234375ms
VM31:142 bulle sort: 18426.757080078125ms
VM31:147 select sort: 20040.4921875ms
VM31:152 insertion sort: 3125.440185546875ms
VM31:157 merge sort: 88.5322265625ms |
测试结果2(10000个元素。注意,多次执行测试结果会不一样,但能看出大概性能)// Prepare
var ARRAY_LENGTH = 10000;
var MAX_VALUE = ARRAY_LENGTH * 10;
var arr = new Array(ARRAY_LENGTH).fill(0).map(x => Math.floor(Math.random() * MAX_VALUE));
// Test quick sort
console.time('quick sort');
quickSort(arr);
console.timeEnd('quick sort');
// Test bulle sort
console.time('bulle sort');
bubbleSort(arr);
console.timeEnd('bulle sort');
// Test select sort
console.time('select sort');
bubbleSort(arr);
console.timeEnd('select sort');
// Test insertion sort
console.time('insertion sort');
insertionSort(arr);
console.timeEnd('insertion sort');
// Test merge sort
console.time('merge sort');
mergeSort(arr);
console.timeEnd('merge sort');
VM205:9 quick sort: 10.051025390625ms
VM205:14 bulle sort: 170.559326171875ms
VM205:19 select sort: 166.6318359375ms
VM205:24 insertion sort: 36.0068359375ms
VM205:29 merge sort: 3.9580078125ms |
测试结果3(1000个元素。注意,多次执行测试结果会不一样,但能看出大概性能)// Prepare
var ARRAY_LENGTH = 1000;
var MAX_VALUE = ARRAY_LENGTH * 10;
var arr = new Array(ARRAY_LENGTH).fill(0).map(x => Math.floor(Math.random() * MAX_VALUE));
// Test quick sort
console.time('quick sort');
quickSort(arr);
console.timeEnd('quick sort');
// Test bulle sort
console.time('bulle sort');
bubbleSort(arr);
console.timeEnd('bulle sort');
// Test select sort
console.time('select sort');
bubbleSort(arr);
console.timeEnd('select sort');
// Test insertion sort
console.time('insertion sort');
insertionSort(arr);
console.timeEnd('insertion sort');
// Test merge sort
console.time('merge sort');
mergeSort(arr);
console.timeEnd('merge sort');
VM363:9 quick sort: 0.267822265625ms
VM363:14 bulle sort: 1.2568359375ms
VM363:19 select sort: 1.27490234375ms
VM363:24 insertion sort: 0.412109375ms
VM363:29 merge sort: 0.43603515625ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
排序算法
快速排序
冒泡排序
选择排序
插入排序
归并排序
性能测试
The text was updated successfully, but these errors were encountered: