Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash multiple iteration sort vs multiple array.prototype.sort
(version: 0)
Comparing performance of:
_.sortBy vs array.prototype.sort
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js'></script>
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for(var i = 0; i < 100000; i++){ arr.push({value1:getRandomInt(100),value2:getRandomInt(100),value3:getRandomInt(100),value4:getRandomInt(100),value5:getRandomInt(100)}); }
Tests:
_.sortBy
_.sortBy(arr,["value1","value2","value3","value4","value5"]);
array.prototype.sort
arr.sort((a,b) => a.value1 - b.value1); arr.sort((a,b) => a.value2 - b.value2); arr.sort((a,b) => a.value3 - b.value3); arr.sort((a,b) => a.value4 - b.value4); arr.sort((a,b) => a.value5 - b.value5);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.sortBy
array.prototype.sort
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):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark compares two approaches: using Lodash's `sortBy` function versus multiple array prototype methods for sorting. **Tested Options** The benchmark tests the following options: 1. **Lodash's `sortBy` function**: This option uses the `sortBy` function from Lodash to sort the array. 2. **Multiple array prototype methods**: This option sorts the array using four separate `sort` methods, each with a different comparison function. **Pros and Cons** **Lodash's `sortBy` function:** Pros: * More concise and readable code * Less error-prone due to Lodash's built-in type checking * Often faster than manual implementation Cons: * Requires an external library (Lodash) * May not be as performant in extreme cases or with very large datasets * Can be slower for smaller datasets due to overhead of the function call **Multiple array prototype methods:** Pros: * No external dependencies required * More control over the sorting process * Can be faster for very large datasets or specific use cases Cons: * Code can become cluttered and harder to read * Error-prone due to manual implementation * May require more effort to optimize performance **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string formatting, and object creation. The `sortBy` function is one of its most useful tools, allowing developers to easily sort arrays based on specific criteria. **Special JS Feature/Syntax** This benchmark does not use any special JavaScript features or syntax beyond what's standard in modern browsers. **Other Alternatives** If you're interested in exploring alternative approaches to sorting, consider the following: 1. **Using `Array.prototype.sort()` with a custom comparator**: This approach involves creating a custom function that takes two elements as input and returns a value indicating their order. 2. **Using `Array.prototype.reduce()` for sorting**: While not exactly equivalent to manual sorting, `reduce()` can be used to sort arrays by applying a cumulative operation to each element in the array. Keep in mind that these alternatives may require more setup and expertise than using Lodash's `sortBy` function or multiple array prototype methods.
Related benchmarks:
Lodash sort vs array.prototype.sort - 2
Lodash orderBy() vs array.prototype.sort
Lodash sort vs array.prototype.sort with localeCompare
Lodash sort vs array.prototype.sort strings
Lodash sort vs array.prototype.sort 3
Comments
Confirm delete:
Do you really want to delete benchmark?