Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lo-Dash _.sortBy() vs Vanilla .sort() vs Vanilla CUSTOM sort method
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Lo-Dash sortBy()
953611.5 Ops/sec
Vanilla sort()
6857806.5 Ops/sec
Vanilla CUSTOM sort method
9646391.0 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
window.users = [ { name: 'Ваня', level: '3' }, { name: 'Саша', level: '1' }, { name: 'Маша', level: '2' }, { name: 'Ника', level: '3' }, { name: 'Вера', level: '1' }, { name: 'Саша', level: '2' }, { name: 'Ваня', level: '2' } ]; window.sortBy = (key) => { return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0); }; function insertionSort(array, fieldName) { let { length } = array, items = []; let i, j, current; while (length--) { items[length] = array[length]; } for (i = 1; i < length; i++) { current = items[i]; j = i; while (j > 0 && getItem(items[j - 1], fieldName) > getItem(current, fieldName)) { items[j] = items[j - 1]; j--; } items[j] = current; } return items; } function getItem(item, fieldName) { if (fieldName) { item = item[fieldName] } return item; }
Tests:
Lo-Dash sortBy()
_.sortBy(users, 'name');
Vanilla sort()
users.sort(sortBy("name"));
Vanilla CUSTOM sort method
insertionSort(users, "name");