Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
intersect v3c
(version: 0)
Comparing performance of:
a vs b vs c
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
Array.prototype.shuffle = function() { let m = this.length, i; while (m) { i = (Math.random() * m--) >>> 0; [this[m], this[i]] = [this[i], this[m]] } return this; }; var watched = []; for(let i = 0; i < 2000; i++){watched.push({programId:Math.random()});} var ignored = [...watched]; ignored.shuffle(); ignored = ignored.slice(0);//50000, 51000);
Tests:
a
watched.filter(wObj => { return !ignored.some((iObj, ndx) => { return iObj.programId === wObj.programId; }); });
b
watched.filter(wObj => !ignored.some((iObj, ndx) => { if (iObj.programId === wObj.programId) { ignored[ndx].programId = ignored.pop().programId; return true; } return false; }) );
c
var iset = new Set(ignored.flatMap(obj => obj.parentId)); watched.filter(wObj => !iset.has(wObj.parentId));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
a
b
c
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
a
630.5 Ops/sec
b
11370.2 Ops/sec
c
58629.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** MeasureThat.net provides a platform for JavaScript microbenchmarks, allowing users to compare different approaches and libraries in their performance. The provided benchmark definition and test cases focus on finding the most efficient way to filter an array of objects based on certain conditions. **Benchmark Definition Explanation** The benchmark definition includes three scripts: 1. **Script Preparation Code**: This code shuffles the `watched` array, which contains 2000 objects with random `programId` values. 2. **Html Preparation Code**: There is no HTML preparation code provided, suggesting that this benchmark is purely JavaScript-related. 3. **Raw UA String and Browser Info**: The raw UA string indicates the browser version (Chrome 125) and device platform (Desktop), as well as operating system (Windows). **Test Cases Explanation** The three test cases aim to find the most efficient way to filter the `watched` array based on different conditions: 1. **Test Case "a"`: Uses the `filter()` method without any additional logic. 2. **Test Case "b"`: Introduces an additional check using the `some()` method, which returns a boolean indicating whether at least one element in the array passes the test. 3. **Test Case "c"`: Uses a `Set` to store the ignored object IDs and then filters out objects whose ID is present in the set. **Options Compared** The benchmark compares three different approaches: 1. **Direct filtering using filter()**: The simplest approach, which uses the `filter()` method to remove elements that do not match the condition. 2. **Using some() with conditional check**: An additional step is introduced by checking if an object's ID matches any ignored IDs using the `some()` method and a conditional statement. 3. **Using Set for efficient lookup**: The third approach uses a `Set` to store the ignored object IDs, allowing for faster lookups when filtering out objects. **Pros and Cons of Each Approach** 1. **Direct filtering using filter()**: * Pros: Simple and straightforward. * Cons: May have performance issues with large arrays due to the overhead of iterating over all elements. 2. **Using some() with conditional check**: * Pros: Allows for a simple and intuitive way to handle nested conditions. * Cons: Introduces additional overhead due to the extra iteration and conditional checks. 3. **Using Set for efficient lookup**: * Pros: Offers the best performance by allowing for O(1) lookups in the set, reducing the number of iterations needed to filter out objects. * Cons: Requires an initial setup step to create the `Set`, which may add overhead. **Library and Special JS Features Used** The benchmark uses a custom implementation of the `shuffle()` method on the `Array.prototype`. No external libraries or special JavaScript features are used. **Alternatives** Other alternatives for filtering arrays could include: * Using `reduce()` or `forEach()` with a callback function * Utilizing `Map` instead of `Set` for efficient lookup * Leveraging modern JavaScript features like `Array.prototype.map()` and `Array.prototype.find()` * Employing parallel processing or concurrency to speed up filtering operations Keep in mind that the best approach will depend on the specific use case, data structure, and performance requirements.
Related benchmarks:
intersect v2c
intersect v2d
intersect v3
intersect v3b
Comments
Confirm delete:
Do you really want to delete benchmark?