Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Shuffled Array Cache Test
(version: 0)
Comparing performance of:
Sorted vs Shuffled
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var sorted = new Array(200000); var shuffled = new Array(200000); class Vector { constructor() { this.x = 0; this.y = 0; this.z = 0; } } for (let i=0; i<200000; i++) { const obj = { position: new Vector(), scale: new Vector(), rotation: new Vector() }; sorted[i] = obj; shuffled[i] = obj; } for (let i=0; i<200000; i++) { const index = Math.floor(Math.random() * 200000); const temp = shuffled[i]; shuffled[i] = shuffled[index]; shuffled[index] = temp; }
Tests:
Sorted
for (let i=0; i<200000; i++) { if (sorted[i].position) {} }
Shuffled
for (let i=0; i<200000; i++) { if (shuffled[i].position) {} }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Sorted
Shuffled
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Sorted
66.0 Ops/sec
Shuffled
45.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The benchmark definition represents a JavaScript code snippet that creates an array of 200,000 objects with `position`, `scale`, and `rotation` properties. The code then shuffles this array using a Fisher-Yates shuffle algorithm. The benchmark measures the execution time of two different test cases: 1. "Sorted": This test case checks if the array is sorted after the shuffle operation. 2. "Shuffled": This test case checks if the shuffled array has any objects with missing `position` properties. **Options Compared** The two test cases compare the performance of two different approaches to verify the correctness of the shuffle operation: 1. **Sorted**: This approach assumes that the array is sorted after shuffling and checks for this condition. 2. **Shuffled**: This approach verifies that at least one object in the shuffled array has a missing `position` property, indicating that the shuffle was not successful. **Pros and Cons** **Sorted:** Pros: * Simple and easy to implement * Verifies that the array is sorted after shuffling Cons: * May fail if the shuffle operation is not deterministic (i.e., the same input may produce different outputs) * May be slower than other approaches due to the additional check for sorting **Shuffled:** Pros: * More robust and less prone to false positives * Can detect non-deterministic shuffles or failures Cons: * More complex and harder to implement * May be slower than simpler approaches due to the additional checks **Other Considerations** * The benchmark uses a Fisher-Yates shuffle algorithm, which is considered one of the most efficient and unbiased shuffling algorithms. * The use of a `Vector` class with `position`, `scale`, and `rotation` properties adds an extra layer of complexity to the benchmark. **Libraries and Special JS Features** The benchmark does not rely on any specific libraries or features. However, it does utilize JavaScript's built-in `Math.random()` function for generating random indices during shuffling. **Alternatives** Other alternatives for shuffling arrays in JavaScript include: * The Fisher-Yates shuffle algorithm (used in this benchmark) * The Knuth shuffle algorithm * The Dutch National Railways shuffle algorithm These algorithms are designed to be efficient and unbiased, but their performance may vary depending on the specific use case and requirements. In summary, the "Shuffled Array Cache Test" benchmark compares two approaches to verify the correctness of a Fisher-Yates shuffle algorithm. While the "Sorted" approach is simple and easy to implement, it may not be as robust as the "Shuffled" approach, which detects non-deterministic shuffles or failures.
Related benchmarks:
Shuffled Array Cache
Shuffled Array Cache Test 2
Shuffled Array Cache Test 3
Shuffled Array Cache Test 4
Comments
Confirm delete:
Do you really want to delete benchmark?