Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fix Lodash_4.17.21.sortBy vs .sort vs custom insertion vs custom quick
(version: 0)
Comparing performance of:
Lodash_4.17.21.sortBy vs stdSort vs InsertionSort vs QuickSort
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
var arr = [{ name: "Ваня", date: "2024-12-01 18:00", curr: "RUB", level: 12, }, { name: "Маня", date: "2024-12-01 02:00", curr: "KZT", level: 3, }, { name: "Петя", date: "2024-12-01 12:00", curr: "USD", level: 7, }, { name: "Вика", date: "2024-12-01 05:00", curr: "RUB", level: 9, }, { name: "Лера", date: "2024-12-01 11:00", curr: "RUB", level: 2, }, { name: "Каша", date: "2024-12-01 15:00", curr: "KZT", level: 10, }, { name: "Паша", date: "2024-12-01 17:00", curr: "USD", level: 1, }, { name: "Даша", date: "2024-12-01 10:00", curr: "RUB", level: 8, }, { name: "Вера", date: "2024-12-01 00:00", curr: "RUB", level: 5, }, { name: "Саша", date: "2024-12-01 14:00", curr: "USD", level: 11, }, { name: "Маша", date: "2024-12-01 10:00", curr: "KZT", level: 4, }, { name: "Ваня", date: "2024-12-01 15:00", curr: "USD", level: 6, }, ]; var CURR_ORDER = { RUB: 1, USD: 2, KZT: 3, }; var CONDITIONS = [ (a, b) => CURR_ORDER[a.curr] - CURR_ORDER[b.curr], (a, b) => new Date(a.date) - new Date(b.date), ]; var compare = (conditions) => (a, b) => { for (let i = 0; i < conditions.length; i++) { const condition = conditions[i]; const type = typeof condition; if (type === "string") { if (typeof a[condition] === "string") { const result = a[condition].localeCompare(b[condition]); if (!result) continue; return result; } else if (typeof a[condition] === "number") { const result = a[condition] - b[condition]; if (!result) continue; return result; } } else if (type === "function") { const result = condition(a, b); if (!result) continue; return result; } } return 0; }; var stdSort = (arr, conditions) => { const newArr = [...arr]; newArr.sort(compare(conditions)); return newArr; }; var insertionSort = (arr, conditions) => { const newArr = [...arr]; for (let i = 1, l = newArr.length; i < l; i++) { const current = arr[i]; let j = i; const comp = compare(conditions); while (j > 0 && comp(newArr[j - 1], current)) { newArr[j] = newArr[j - 1]; j--; } newArr[j] = current; } return newArr; }; var partition = (arr, start, end, compare) => { const pivotValue = arr[end]; let pivotIndex = start; for (let i = start; i < end; i++) { if (compare(arr[i], pivotValue) < 0) { [arr[i], arr[pivotIndex]] = [arr[pivotIndex], arr[i]]; pivotIndex++; } } [arr[pivotIndex], arr[end]] = [arr[end], arr[pivotIndex]]; return pivotIndex; }; var quickSortIterative = (arr, conditions) => { const newArr = [...arr]; const stack = [0, arr.length - 1]; const comp = compare(conditions); while (stack[stack.length - 1] >= 0) { end = stack.pop(); start = stack.pop(); pivotIndex = partition(newArr, start, end, comp); if (pivotIndex - 1 > start) { stack.push(start); stack.push(pivotIndex - 1); } if (pivotIndex + 1 < end) { stack.push(pivotIndex + 1); stack.push(end); } } return newArr; };
Tests:
Lodash_4.17.21.sortBy
_.sortBy(arr, [(o) => CURR_ORDER[o.curr], (o) => new Date(o.date)]);
stdSort
stdSort(arr, CONDITIONS);
InsertionSort
insertionSort(arr, CONDITIONS);
QuickSort
quickSortIterative(arr, CONDITIONS);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash_4.17.21.sortBy
stdSort
InsertionSort
QuickSort
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash_4.17.21.sortBy
69234.9 Ops/sec
stdSort
51185.3 Ops/sec
InsertionSort
37954.9 Ops/sec
QuickSort
35353.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
A challenging benchmarking result! To provide an accurate analysis, I'll focus on the latest benchmark result: **Latest Benchmark Result:** [ { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "Browser": "Chrome 121", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 69234.875, "TestName": "Lodash_4.17.21.sortBy" }, { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "Browser": "Chrome 121", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 51185.33203125, "TestName": "stdSort" }, { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "Browser": "Chrome 121", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 37954.8515625, "TestName": "InsertionSort" }, { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "Browser": "Chrome 121", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 35353.5, "TestName": "QuickSort" } ] **Key Observations:** 1. **Lodash (4.17.21)** is the fastest implementation, with an average execution speed of 69,234.875 executions per second. 2. The **stdSort** method is significantly slower than Lodash, with an average execution speed of 51,185.33203125 executions per second. 3. **Insertion Sort** has a relatively low execution speed of 37,954.8515625 executions per second. 4. **Quick Sort** is the slowest implementation, with an average execution speed of 35,353.5 executions per second. Based on these results, it appears that Lodash (4.17.21) is the fastest and most efficient sorting algorithm among the four implementations tested.
Related benchmarks:
_.sortBy vs native sort
lodash vs es6 in sort method
order desc with lodash orderBy vs es6 sort method
Lodash_4.17.21.sortBy vs .sort vs custom insertion vs custom quick
Comments
Confirm delete:
Do you really want to delete benchmark?