Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Shuffled Array Cache Test 3
(version: 0)
Comparing performance of:
Shuffled vs Shuffled const vs Sorted vs Sorted const
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++) { const obj = shuffled[i]; if (obj.position.x === 0 && obj.position.y === 0 && obj.position.z === 0) {} }
Shuffled const
for (let i=0; i<200000; i++) { const obj = shuffled[i]; const position = obj.position; if (position.x === 0 && position.y === 0 && position.z === 0) {} }
Sorted
for (let i=0; i<200000; i++) { const obj = sorted[i]; if (obj.position.x === 0 && obj.position.y === 0 && obj.position.z === 0) {} }
Sorted const
for (let i=0; i<200000; i++) { const obj = sorted[i]; const position = obj.position; if (position.x === 0 && position.y === 0 && position.z === 0) {} }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Shuffled
Shuffled const
Sorted
Sorted const
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
Shuffled
25.0 Ops/sec
Shuffled const
25.9 Ops/sec
Sorted
67.9 Ops/sec
Sorted const
69.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is designed to measure the performance of JavaScript engines in comparing two arrays: `sorted` and `shuffled`. The arrays contain 200,000 objects with three vectors (x, y, z) each. The script preparation code creates both arrays and shuffles the second array using a Fisher-Yates shuffle algorithm. This ensures that the order of elements is randomized. **Options Compared** There are four test cases: 1. **Shuffled**: This test case compares the shuffled array directly to itself. 2. **Shuffled const**: This test case uses `const` keyword when comparing the shuffled array elements with their positions. 3. **Sorted**: This test case compares the sorted array directly to itself. 4. **Sorted const**: This test case uses `const` keyword when comparing the sorted array elements with their positions. **Pros and Cons of Each Approach** 1. **Shuffled**: This approach has a higher chance of finding identical pairs, making it slower due to unnecessary comparisons. However, it's more likely to find matches in random data. 2. **Shuffled const**: By using `const`, the comparison is made only when necessary (i.e., when an element doesn't match its position). This reduces unnecessary computations and makes it faster than `Shuffled`. 3. **Sorted**: Similar to `Shuffled`, this approach finds identical pairs more frequently, making it slower due to unnecessary comparisons. 4. **Sorted const**: Like `Shuffled const`, this approach uses `const` for efficient comparisons. **Special JS Features/Syntax** There are no specific JavaScript features or syntaxes being tested in this benchmark. However, the use of `class` and object literals (`const obj = { position: new Vector(), scale: new Vector(), rotation: new Vector() }`) is typical for modern JavaScript development. **Alternatives** Other alternatives to test array comparison performance could include: * Comparing arrays using built-in `every()` or `some()` methods. * Using data structures like sets, which would eliminate duplicate comparisons. * Implementing a custom algorithm to find identical pairs, potentially faster than the existing approaches. The provided benchmark is designed to measure the efficiency of JavaScript engines in performing simple array comparison tasks.
Related benchmarks:
Shuffled Array Cache
Shuffled Array Cache Test
Shuffled Array Cache Test 2
Shuffled Array Cache Test 4
Comments
Confirm delete:
Do you really want to delete benchmark?