Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
intersect v1
(version: 0)
Comparing performance of:
naive compare vs some; swap and shorten len vs for; swap and shorten len
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var watched = []; var ignored = []; for(let i = 0; i < 10000; i++){watched.push({programId:Math.random()});} for(let i = 0; i < 10000; i++){ignored.push({programId:Math.random()});}
Tests:
naive compare
watched.filter(wObj => { return !ignored.some((iObj, ndx) => iObj.programId === wObj.programId); });
some; swap and shorten len
let ml = ignored.length -1; watched.filter(wObj => !ignored.some((iObj, ndx) => { if (iObj.programId === wObj.programId) { ignored[ndx].programId = ignored[ml--].programId; ignored.length = ml; return true; } return false; }) );
for; swap and shorten len
let ml = ignored.length -1; watched.filter(wObj => { for (let i = 0; i < ml; i++) { if (wObj.programId === ignored[i].programId) { ignored[i].programId = ignored[ml--].programId; return false; } } return true; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
naive compare
some; swap and shorten len
for; swap and shorten len
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
naive compare
11.8 Ops/sec
some; swap and shorten len
8.6 Ops/sec
for; swap and shorten len
0.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark measures the performance of three different algorithms for intersecting two arrays: `watched` and `ignored`. The arrays contain 10,000 random program IDs. **Algorithms Compared** 1. **Naive Compare**: This algorithm uses a simple iterative approach to filter out matching elements in both arrays. 2. **Some; Swap and Shorten Len**: This algorithm uses the `some()` method to check for matches and then iteratively swaps and shortens the `ignored` array until no matches are found. 3. **For; Swap and Shorten Len**: Similar to the previous one, but uses a `for` loop instead of `some()`. **Options Compared** * Iterative vs. Functional Programming Approach: The algorithms differ in their use of iteration (naive compare) or functional programming techniques (some; swap and shorten len). * Use of Built-in Methods: Some algorithms use built-in methods like `some()` and `length` (some; swap and shorten len), while others rely on explicit loops (naive compare, for; swap and shorten len). **Pros and Cons** * **Naive Compare**: + Pros: Simple, easy to understand. + Cons: Inefficient use of iteration can lead to slow performance. * **Some; Swap and Shorten Len**: + Pros: Uses built-in methods, potentially more efficient than naive compare. + Cons: May have higher overhead due to function calls. * **For; Swap and Shorten Len**: + Pros: Similar to some; swap and shorten len, but potentially more efficient. + Cons: Less intuitive for developers familiar with iterative approaches. **Library Usage** None of the provided algorithms rely on external libraries. However, they do use built-in JavaScript methods like `some()` and `length`. **Special JS Features/Syntax** * None mentioned in this explanation. **Other Alternatives** * Other intersection algorithms can be considered, such as using `filter()` or `reduce()`. * Using a more efficient data structure, like a hash table, could also improve performance. * Multi-threading or parallel processing techniques might further accelerate the benchmark results.
Related benchmarks:
intersect v2c
intersect v2d
intersect v3
intersect v3c
Comments
Confirm delete:
Do you really want to delete benchmark?