Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Shuffled Array Cache
(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(1000000); var shuffled = new Array(1000000); class Vector { constructor() { this.x = 0; this.y = 0; this.z = 0; } } for (let i=0; i<1000000; i++) { const obj = { position: new Vector(), scale: new Vector(), rotation: new Vector() }; sorted[i] = obj; shuffled[i] = obj; } for (let i=0; i<1000000; i++) { const index = Math.floor(Math.random() * 1000000); const temp = shuffled[i]; shuffled[i] = temp; shuffled[index] = temp; }
Tests:
Sorted
for (let i=0; i<1000000; i++) { if (sorted[i].position) {} }
Shuffled
for (let i=0; i<1000000; 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
13.8 Ops/sec
Shuffled
7.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark measures the performance difference between two approaches: accessing an array using its sorted index versus shuffling the index. The benchmark is represented by a JSON object that defines the test case and script preparation code. **Script Preparation Code Analysis** The script preparation code creates: 1. A 1 million element array `sorted` containing objects with `position`, `scale`, and `rotation` properties. 2. Another 1 million element array `shuffled` initialized with the same objects as `sorted`. 3. A custom `Vector` class with `x`, `y`, and `z` properties. The script then performs two for loops: 1. The first loop assigns an object to each index in both `sorted` and `shuffled` arrays. 2. The second loop shuffles the elements of the `shuffled` array by swapping random pairs of indices. **Options Compared** Two options are compared: 1. **Sorted**: Accessing an array using its sorted index, which means iterating through the array in order. 2. **Shuffled**: Accessing an array using a shuffled index, which means iterating through the array with randomized access. **Pros and Cons of Each Approach** * **Sorted**: + Pros: Generally faster since the compiler or interpreter can optimize for sequential iteration. + Cons: May not be as efficient if the data is too large to fit in cache or if there are many random accesses. * **Shuffled**: + Pros: Can be beneficial when accessing a large dataset with random indices, such as in certain machine learning or scientific computing applications. + Cons: Typically slower due to the overhead of shuffling and indexing. **Library and Special JS Feature** There is no explicit mention of any libraries used in this benchmark. However, it's possible that some internal JavaScript optimizations are being utilized, especially for Chrome 119. **Device Platform and Browser** The benchmark is run on a desktop platform with Google Chrome 119 browser. **Other Alternatives** If you wanted to create a similar benchmark, consider the following alternatives: 1. Measure access times using different data structures, such as arrays versus linked lists. 2. Compare iteration methods for specific types of data, like strings or numbers. 3. Investigate performance differences between JavaScript engines, including WebKit (used by Chrome and Safari) and SpiderMonkey (used by Firefox). 4. Consider adding more complex operations to the script preparation code, like sorting and searching large datasets. Keep in mind that this benchmark is focused on a specific use case (randomized array access), so it may not be directly applicable to other scenarios.
Related benchmarks:
Shuffled Array Cache Test
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?