Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash shuffle
(version: 0)
Comparing performance of:
JS vs L
Created:
6 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 shuffle(a) { var j, x, i; for (i = a.length; i; i--) { j = Math.floor(Math.random() * i); x = a[i - 1]; a[i - 1] = a[j]; a[j] = x; } return a } var all = []; var allLength = 10000; for(var i = 0; i < allLength; i++) { all[i] = i; }
Tests:
JS
shuffle(all);
L
_.shuffle(all)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JS
L
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JS
13076.4 Ops/sec
L
11139.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark definition is a piece of JavaScript code that shuffles an array using either the built-in `shuffle` function or the `_` library's `shuffle` function from Lodash. The array to be shuffled has 10,000 elements, ranging from 0 to 9,999. **Options being compared** There are two options being compared: 1. **Built-in JavaScript implementation**: The `shuffle` function is implemented using a simple iterative approach that uses the Fisher-Yates shuffle algorithm. 2. **Lodash library implementation**: The `_` library's `shuffle` function provides a more robust and efficient implementation of the same algorithm. **Pros and cons of each approach** 1. **Built-in JavaScript implementation** * Pros: + Native performance, as it's implemented in the browser's JavaScript engine. + Simple to implement and understand. * Cons: + May not be optimized for performance or have built-in optimizations like Lodash. 2. **Lodash library implementation** * Pros: + Well-tested and optimized by a large community of developers. + Provides additional functionality, such as handling edge cases and larger arrays. * Cons: + Requires an external dependency (the Lodash library). + May introduce overhead due to the inclusion of extra code. **Other considerations** 1. **Browser differences**: The benchmark is run on a Mac OS X system with Chrome 128, which may not be representative of other platforms or browsers. 2. **Device platform**: Running the benchmark on a desktop device may differ from running it on a mobile device. 3. **JavaScript engine optimization**: The performance difference between the two implementations might be influenced by the browser's JavaScript engine optimization techniques. **Library and its purpose** The `_` library is a utility belt for functional programming in JavaScript, providing a collection of helper functions that make common tasks easier. In this case, the `shuffle` function from Lodash is used to shuffle an array, which would otherwise require more code and complexity to implement manually. **Special JS feature or syntax (none)** There are no special JavaScript features or syntaxes being tested in this benchmark. **Alternatives** Some alternative approaches to shuffling arrays could include: 1. **Using a third-party library**: There are many other libraries available that provide efficient array shuffling algorithms, such as `array-shuffle` or `random-array`. 2. **Implementing the shuffle algorithm manually**: A developer could write their own custom implementation of the Fisher-Yates shuffle algorithm to compare with the built-in JavaScript and Lodash implementations. 3. **Using a different data structure**: If possible, using a different data structure, such as a linked list or a tree, might provide more efficient shuffling algorithms.
Related benchmarks:
Lodash sort vs array.prototype.sort (strings)
Lodash sort vs array.prototype.sort (strings) small
Lodash sort vs array.prototype.sort (larger array)
Lodash sort vs array.prototype.sort (Lodash 4.17.15)
Lodash sort vs array.prototype.sort fork for spread
Comments
Confirm delete:
Do you really want to delete benchmark?