Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Sorting test U
(version: 0)
test with 33 items
Comparing performance of:
_.sortBy vs native sort
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for (var i = 0; i < 33; i++) { arr.push({ value: getRandomInt(100) }); }
Tests:
_.sortBy
arr = _.sortBy(arr,"value");
native sort
arr = arr.sort((a,b) => a.value > b.value);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.sortBy
native 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):
I'll break down the provided JSON data to explain what's being tested and the options compared. **Benchmark Definition** The benchmark is defined by two test cases: `_.sortBy` and `native sort`. The script preparation code generates an array of 33 random objects with a unique value between 0 and 100. This creates a simple yet representative dataset for testing sorting algorithms. **Options Compared** Two options are compared: 1. **_.sortBy**: Uses the Lodash library's `sortBy` function to sort the array. 2. **Native Sort**: Uses the built-in JavaScript `sort()` method, which relies on the browser's internal implementation. **Pros and Cons of Each Approach** ### _.sortBy Pros: * Portable: The Lodash library is a popular and widely supported utility library that can be easily included in projects. * Efficient: The `_sortBy` function is optimized for performance and should provide good results. Cons: * Additional Library Dependency: Using Lodash adds an extra dependency to the project, which might not be desirable for smaller or more minimalist applications. * Potential Performance Overhead: While optimized, some developers might still worry about the additional overhead of including a library. ### Native Sort Pros: * Built-in Performance: The built-in `sort()` method is often implemented in the browser's engine and can take advantage of native optimizations. * No Additional Dependencies: Since it's built-in, there are no extra dependencies to consider. Cons: * Browser-Specific: The performance of the native sort can vary depending on the browser implementation. * Platform Limitations: Native sorting might not work as expected in certain browsers or environments (e.g., some older browsers). **Library and Purpose** The `_` is a reference to Lodash, a popular JavaScript utility library. The `sortBy` function takes an array and a key function as arguments, allowing you to specify the attribute to sort by. In this benchmark, `_.sortBy` is used to sort the generated array based on the value property of each object. **Special JS Feature or Syntax** There's no special JS feature or syntax being tested in this benchmark. The focus is solely on comparing two sorting algorithms: one built-in (native) and another from a library (`_.sortBy`).
Related benchmarks:
Comparing _orderBy with native sort
_orderBy vs javascript arr.sort
Lodash 4.17.21 sort vs array.prototype.sort
sort variants test
Comments
Confirm delete:
Do you really want to delete benchmark?