Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy two items
(version: 0)
Lodash sortBy vs orderBy
Comparing performance of:
_.sortBy vs _.orderBy
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var arr = [{"id":"OSIRIS:458887500","sourceId":"OSIRIS:33329034","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"INACTIVE","statusSubCode":"TA","startDate":"2019-11-26T07:00:00.000+0000","endDate":"2019-12-31T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:467315777","sourceId":"OSIRIS:33439501","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"CO","startDate":"2020-06-30T07:00:00.000+0000","endDate":"2020-08-04T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:462817595","sourceId":"OSIRIS:33389355","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"INACTIVE","statusSubCode":"TA","startDate":"2020-03-03T07:00:00.000+0000","endDate":"2020-04-07T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:456995316","sourceId":"OSIRIS:33297697","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"CO","startDate":"2019-09-17T07:00:00.000+0000","endDate":"2019-10-22T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:457873887","sourceId":"OSIRIS:33313719","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"INACTIVE","statusSubCode":"TA","startDate":"2019-10-22T07:00:00.000+0000","endDate":"2019-11-26T06:59:59.000+0000","grade":"W","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:465167129","sourceId":"OSIRIS:33425311","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"CO","startDate":"2020-04-14T07:00:00.000+0000","endDate":"2020-05-19T06:59:59.000+0000","grade":"A","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:465269457","sourceId":"OSIRIS:33426359","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"CO","startDate":"2020-04-07T07:00:00.000+0000","endDate":"2020-05-12T06:59:59.000+0000","grade":"A","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:467315864","sourceId":"OSIRIS:33439707","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"SC","startDate":"2020-06-23T07:00:00.000+0000","endDate":"2020-07-28T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:466599703","sourceId":"OSIRIS:33434895","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"SC","startDate":"2020-07-07T07:00:00.000+0000","endDate":"2020-08-11T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:466906728","sourceId":"OSIRIS:33437054","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"SC","startDate":"2020-07-14T07:00:00.000+0000","endDate":"2020-08-18T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:465951331","sourceId":"OSIRIS:33430607","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"CO","startDate":"2020-05-05T07:00:00.000+0000","endDate":"2020-06-09T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:468475926","sourceId":"OSIRIS:33446501","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"SC","startDate":"2020-07-28T07:00:00.000+0000","endDate":"2020-09-01T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:462579348","sourceId":"OSIRIS:33389889","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"INACTIVE","statusSubCode":"TA","startDate":"2020-03-03T07:00:00.000+0000","endDate":"2020-04-07T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:468783166","sourceId":"OSIRIS:33369450","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"SC","startDate":"2019-12-10T07:00:00.000+0000","endDate":"2020-01-28T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:460988266","sourceId":"OSIRIS:33364232","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"INACTIVE","statusSubCode":"TA","startDate":"2020-01-21T07:00:00.000+0000","endDate":"2020-02-25T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:462783613","sourceId":"OSIRIS:33392948","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"CO","startDate":"2020-02-10T07:00:00.000+0000","endDate":"2020-03-16T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"OSIRIS:462851478","sourceId":"OSIRIS:33393967","sourceType":"SECTION","personId":"626488414876553216","studentProgramId":"4862081","roleType":"Student","status":"ACTIVE","statusSubCode":"SC","startDate":"2020-04-14T07:00:00.000+0000","endDate":"2020-05-13T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"SDW:9052209","sourceId":"SDW:13391630","sourceType":"SECTION","personId":"626488414876553216","roleType":"Student","status":"SC","startDate":"2020-11-05T07:00:00.000+0000","endDate":"2020-11-20T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"SDW:9052209","sourceId":"SDW:13391629","sourceType":"SECTION","personId":"626488414876553216","roleType":"Student","status":"SC","startDate":"2020-10-29T07:00:00.000+0000","endDate":"2020-11-05T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"},{"id":"SDW:9052209","sourceId":"SDW:13391132","sourceType":"SECTION","personId":"626488414876553216","roleType":"Student","status":"DR","startDate":"2020-03-15T07:00:00.000+0000","endDate":"2020-03-23T06:59:59.000+0000","profileId":"a65c500c-57c6-4d73-a535-dbf09f868362"}];
Tests:
_.sortBy
_.sortBy(arr,["startDate", "endDate"]);
_.orderBy
_.orderBy(arr,["startDate", "endDate"]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.sortBy
_.orderBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It looks like we have a JSON string containing an array of objects representing student records, along with some benchmarking information and a code snippet for HTML preparation. To answer your question, I'll focus on the `_.sortBy` and `_.orderBy` functions from Lodash. Assuming these functions are implemented correctly, here's a possible implementation in JavaScript: ```javascript function sortBy(arr, keys) { return arr.sort((a, b) => { for (const key of keys) { const aValue = a[key]; const bValue = b[key]; if (aValue !== bValue) { return aValue < bValue ? -1 : 1; } } return 0; }); } function orderBy(arr, keys) { return sortBy(arr, keys).reverse(); } ``` Using these functions, we can rewrite the benchmarking code to: ```javascript const data = JSON.parse(dataString); console.log(_.sortBy(data, ['startDate', 'endDate'])); console.log(_.orderBy(data, ['startDate', 'endDate'])); ``` This should produce the expected output for `_.sortBy` and `_.orderBy`. Note that I'm assuming the `dataString` contains a valid JSON representation of the student records array. As for the actual execution times, based on the provided results, it appears that: * `_.orderBy` is slightly faster than `_.sortBy`, with an average execution time of 179.4 executions per second compared to 170.8 seconds. * The fastest browser, Chrome 86 on a Mac, outperforms other browsers in terms of execution speed. Please note that these results are based on the provided benchmarking data and may not be representative of real-world performance.
Related benchmarks:
_.SortBy vs Sort
lodash vs es6 in sort method
Lodash sortBy vs orderBy one item vs two item
order desc with lodash orderBy vs es6 sort method
Comments
Confirm delete:
Do you really want to delete benchmark?