Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Shuffled Array Cache Test 4
(version: 0)
Comparing performance of:
Sorted vs Shuffled vs Shuffled reorder
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++) { const obj = sorted[i]; if (obj.position.x === 0) {} }
Shuffled
for (let i=0; i<200000; i++) { const obj = shuffled[i]; if (obj.position.x === 0) {} }
Shuffled reorder
const reordered = new Array(200000); for (let i=0; i<200000; i++) { reordered[i] = shuffled[i]; } for (let i=0; i<200000; i++) { const obj = reordered[i]; if (obj.position.x === 0) {} }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Sorted
Shuffled
Shuffled reorder
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 16 on iOS 16.7.2
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Sorted
31.2 Ops/sec
Shuffled
14.8 Ops/sec
Shuffled reorder
26.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared options, pros/cons of each approach, and other considerations. **Benchmark Overview** The benchmark measures the performance of accessing elements in an array by their index. There are three test cases: 1. **Sorted**: Accessing elements by their sorted index. 2. **Shuffled**: Accessing elements by their shuffled index. 3. **Shuffled Reorder**: Creating a new shuffled array and then accessing elements by their original index. **Benchmark Definition JSON** The benchmark definition contains two scripts: `Script Preparation Code` and `Html Preparation Code`. The former creates an array of 200,000 objects with properties `position`, `scale`, and `rotation`. The latter is empty. **Individual Test Cases** Each test case has a unique script that implements the access pattern. Let's analyze each one: 1. **Sorted**: This test case simply accesses elements by their sorted index. The script uses a simple loop to access each element in order. 2. **Shuffled**: Similar to the Sorted test, but with shuffled indices. The script uses the same loop as before, but the indices are randomized. 3. **Shuffled Reorder**: This test creates a new shuffled array and then accesses elements by their original index. The script first shuffles the original array using Fisher-Yates shuffle, and then creates a new array from the shuffled indices. **Comparison of Access Patterns** The three access patterns differ in how they handle out-of-bounds or invalid indices: 1. **Sorted**: This test case assumes that all indices are valid and doesn't perform any bounds checking. 2. **Shuffled**: Similar to Sorted, but with randomized indices. 3. **Shuffled Reorder**: This test creates a new array from the shuffled indices, which means it handles out-of-bounds indices by using the original index as a default. **Pros and Cons of Each Approach** 1. **Sorted**: Fastest performance, since access is sequential and predictable. However, it assumes all indices are valid. 2. **Shuffled**: Slower performance due to the randomized indices, but it can handle out-of-bounds indices by using the original index as a default. 3. **Shuffled Reorder**: Slowest performance, since creating a new array from shuffled indices is computationally expensive. However, it handles out-of-bounds indices correctly. **Library and Special JS Features** The benchmark uses a custom `Vector` class to represent 3D positions, scales, and rotations. This library is not part of the standard JavaScript API and is specific to this benchmark. **Other Considerations** * The benchmark uses Mobile Safari 16 as the browser, which may affect performance. * The device platform is set to Mobile, which may influence performance due to limited resources. * The operating system is iOS 16.7.2, which is a relatively recent version and may have optimizations for array access. **Alternatives** If you want to run this benchmark on a different platform or browser, you can: 1. Update the `Script Preparation Code` to use a different data structure or algorithm. 2. Modify the `Html Preparation Code` to change the browser or device platform. 3. Use a different benchmarking framework or tool. Keep in mind that the benchmark's performance results may vary depending on the specific hardware and software configuration.
Related benchmarks:
Shuffled Array Cache
Shuffled Array Cache Test
Shuffled Array Cache Test 2
Shuffled Array Cache Test 3
Comments
Confirm delete:
Do you really want to delete benchmark?