Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Shuffling techniques prequal
(version: 0)
Comparing performance of:
shuffle with unwanted check vs shuffle and concat vs shuffle and push
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src=" https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js "></script>
Tests:
shuffle with unwanted check
const defaultOptions = [ { icon: "icon1", name: "name1", value: "value1" }, { icon: "icon2", name: "name2", value: "value3" }, { icon: "icon3", name: "name3", value: "value3" }, { icon: "icon4", name: "name4", value: "value4" }, { icon: "icon5", name: "name5", value: "value5" }, { icon: "icon6", name: "name6", value: "value6" } ]; const randomizeRadioOptions = (options, wantedAsLastElement) => { const optionsArray = _.shuffle(options); const lastElement = optionsArray.find(x => x.value === wantedAsLastElement); _.remove(optionsArray, x => x.value === wantedAsLastElement); optionsArray.push(lastElement); return optionsArray; }; const newOptions = randomizeRadioOptions(defaultOptions, "value6");
shuffle and concat
const defaultOptions = [ { icon: "icon1", name: "name1", value: "value1" }, { icon: "icon2", name: "name2", value: "value3" }, { icon: "icon3", name: "name3", value: "value3" }, { icon: "icon4", name: "name4", value: "value4" }, { icon: "icon5", name: "name5", value: "value5" }, ] const indecisiveOption = { icon: "icon6", name: "name6", value: "value6" } const newOptions = _.shuffle(defaultOptions).concat(indecisiveOption);
shuffle and push
const defaultOptions = [ { icon: "icon1", name: "name1", value: "value1" }, { icon: "icon2", name: "name2", value: "value3" }, { icon: "icon3", name: "name3", value: "value3" }, { icon: "icon4", name: "name4", value: "value4" }, { icon: "icon5", name: "name5", value: "value5" }, ] const indecisiveOption = { icon: "icon6", name: "name6", value: "value6" } const randomizeRadioOptions = (options, lastElement) => { const shuffledOptions = _.shuffle(options); shuffledOptions.push(lastElement); return shuffledOptions; } const newOptions = randomizeRadioOptions(defaultOptions, indecisiveOption);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
shuffle with unwanted check
shuffle and concat
shuffle and push
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
shuffle with unwanted check
3030869.2 Ops/sec
shuffle and concat
3816999.0 Ops/sec
shuffle and push
6151464.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll provide an in-depth explanation of the benchmark, its test cases, and the different approaches being compared. **Benchmark Overview** The MeasureThat.net benchmark is designed to measure the performance of shuffling techniques for radio button options. The benchmark consists of three test cases: 1. "shuffle with unwanted check" 2. "shuffle and concat" 3. "shuffle and push" Each test case measures the execution time of a JavaScript function that shuffles an array of objects representing radio button options. **Test Case 1: "Shuffle with Unwanted Check"** This test case uses the `_.shuffle` function from the Lodash library to shuffle the `defaultOptions` array. The `_remove` function is then used to remove the first element of the shuffled array (with value `"value6"`). Finally, the last element (also with value `"value6"`) is added back to the end of the array. **Pros and Cons** * **Pros**: This approach avoids unnecessary allocations and copies, as it only shuffles the original array and then modifies it in place. * **Cons**: The `_remove` function can be slower than simply using `splice()` or other array methods, due to its more complex logic. **Test Case 2: "Shuffle and Concat"** This test case uses the `_.shuffle` function from Lodash to shuffle the `defaultOptions` array. The shuffled array is then concatenated with a separate object (`indecisiveOption`) using the `+` operator. **Pros and Cons** * **Pros**: This approach avoids creating a new array, as it modifies the original shuffled array and adds the new element at the end. * **Cons**: Concatenating arrays can be slower than other methods due to the creation of a new intermediate array. **Test Case 3: "Shuffle and Push"** This test case uses the `_.shuffle` function from Lodash to shuffle the `defaultOptions` array. The shuffled array is then pushed with a separate object (`indecisiveOption`) using the `push()` method. **Pros and Cons** * **Pros**: This approach avoids creating intermediate arrays, as it modifies the original shuffled array directly. * **Cons**: Pushing elements onto an array can be slower than other methods due to the allocation of new memory. **Benchmark Results** The latest benchmark results show that: 1. "Shuffle and push" is the fastest test case, with an average execution time of around 3.03 million executions per second. 2. "Shuffle and concat" is slightly slower, with an average execution time of around 3.81 million executions per second. 3. "Shuffle with unwanted check" is the slowest test case, with an average execution time of around 6.15 million executions per second. In general, these results suggest that modifying the original array in place (as in Test Case 1) and using push() or concat() methods can be slower than other approaches due to overheads like array allocations and copies. However, the best approach depends on specific use cases and performance requirements.
Related benchmarks:
uniqBy performance
uniqBy performance ttt
uniqBy performance lodash vs native
uniqBy performance and map
Uniq by sorting test 2
Comments
Confirm delete:
Do you really want to delete benchmark?