Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Dashi's tests
(version: 0)
test between lodash orderBy and custom
Comparing performance of:
_.orderBy vs custom
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.5/lodash.min.js'></script>
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } function getValueAt(object, path) { const pathParts = path.split('.'); return pathParts.reduce((agg, item) => agg && agg[item], object); } function orderBy(data, sortKey, sortValue) { for (let i = 0; i < sortKey.length; i++) { data.sort((a, b) => { if (sortValue[i] === 'asc') { return getValueAt(a, sortKey[i]) > getValueAt(b, sortKey[i]) ? 1 : 0; } if (sortValue[i] === 'desc') { return getValueAt(b, sortKey[i]) < getValueAt(a, sortKey[i]) ? -1 : 0; } }); } return data; } var arr = []; for(var i = 0; i < 100000; i++){ arr.push({data:{value:getRandomInt(100)}}); }
Tests:
_.orderBy
_.orderBy(arr,"data.value", "desc");
custom
orderBy(arr, ["data.value"], ["desc"]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.orderBy
custom
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):
Measuring the performance of JavaScript microbenchmarks is crucial to understand how different approaches and libraries impact execution time. **Benchmark Overview** The provided JSON represents two individual test cases: `_.orderBy` (using Lodash's `orderBy` function) and `custom` (a custom implementation). The benchmark definition defines a script preparation code, which includes functions to generate random integers and get values at specific paths in an object. The HTML preparation code links to the Lodash library. **Options Compared** The two test cases compare the performance of using Lodash's `orderBy` function (`_.orderBy`) versus a custom implementation (`custom`). Both approaches sort an array of objects based on a specific path. **Pros and Cons** * **_.orderBy (Lodash)**: + Pros: Highly optimized, tested, and widely used library with extensive documentation. + Cons: Adds dependency on Lodash, might not be suitable for all use cases (e.g., smaller projects). * **custom**: + Pros: Low overhead, no dependencies, and can be tailored to specific requirements. + Cons: Requires manual implementation of sorting logic, which might lead to errors or performance issues. **Other Considerations** When choosing between these approaches, consider the following: * If you need a lightweight solution for small projects or specific use cases, `custom` might be a better choice. * For larger projects or more complex sorting requirements, Lodash's `orderBy` function is likely a better option due to its proven performance and maintainability. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as string manipulation, array manipulation, and more. The `orderBy` function is part of the `lodash.sortby` module and is used to sort arrays based on specific paths in objects. It's designed to be efficient and flexible while minimizing dependencies. **Special JS Feature/Syntax: Async/Await** Neither test case explicitly uses async/await syntax, so there are no additional considerations for this feature.
Related benchmarks:
Lodash orderBy() vs array.prototype.sort
Lodash orderBy vs array.prototype.sort fork
test custom order vs lodash
Lodash orderBy vs array.prototype.sort vs vanila orderBy
Comments
Confirm delete:
Do you really want to delete benchmark?