Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Shuffled Array Cache Test 2
(version: 0)
Comparing performance of:
Shuffled vs Sorted
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:
Shuffled
for (let i=0; i<200000; i++) { if (shuffled[i].position) {} }
Sorted
for (let i=0; i<200000; i++) { if (sorted[i].position) {} }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Shuffled
Sorted
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
Shuffled
15.7 Ops/sec
Sorted
31.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation. **Benchmark Definition JSON** The provided JSON represents a JavaScript microbenchmark named "Shuffled Array Cache Test 2". It consists of two benchmark definitions: 1. **Script Preparation Code**: This section contains code that prepares the test environment. It creates two arrays, `sorted` and `shuffled`, each with 200,000 elements, and a class `Vector` used to represent object properties. The script then populates these arrays with objects and shuffles the second array. 2. **Html Preparation Code**: This section is empty, indicating that no HTML-related code needs to be executed before running the benchmark. **Individual Test Cases** The JSON also includes two individual test cases: 1. **Shuffled**: This test case measures the performance of accessing an element in the shuffled array using a simple `if` statement. 2. **Sorted**: This test case measures the performance of accessing an element in the sorted array using a similar `if` statement. **Options Compared** The benchmark compares two approaches: 1. **Shuffled Array Access**: This option accesses an element in the shuffled array using a simple `if` statement (`shuffled[i].position`). 2. **Sorted Array Access**: This option accesses an element in the sorted array using the same `if` statement (`sorted[i].position`). **Pros and Cons** * **Shuffled Array Access**: + Pros: Can be faster due to cache locality, as elements are randomly accessed. + Cons: May lead to slower performance due to increased branch prediction misses. * **Sorted Array Access**: + Pros: Typically faster due to better branch prediction, as elements are sequentially accessed. + Cons: May not benefit from cache locality. **Library and Purpose** In the script preparation code, a class `Vector` is defined. This is likely used as a placeholder or a representation of an object property, but its actual purpose depends on the context of the benchmark. The library used here seems to be a custom implementation, rather than a widely recognized one. **Special JS Feature or Syntax** There are no special JavaScript features or syntax used in this benchmark. It only relies on standard ECMAScript features. **Alternatives** Other alternatives for similar benchmarks might include: 1. **Randomized Cache Test**: Instead of shuffling an array, the benchmark could use a randomized cache access pattern. 2. **Sequential Cache Test**: The benchmark could test sequential access patterns in both shuffled and sorted arrays. 3. **Object Property Access Benchmark**: A more general benchmark that tests performance of accessing object properties, rather than specific array indices. Keep in mind that these alternatives might not be directly applicable to the existing benchmark, and new benchmarks should consider their own unique use cases and requirements.
Related benchmarks:
Shuffled Array Cache
Shuffled Array Cache Test
Shuffled Array Cache Test 3
Shuffled Array Cache Test 4
Comments
Confirm delete:
Do you really want to delete benchmark?