Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
intersect v2b
(version: 0)
Comparing performance of:
some vs some; pop and swap
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 < 100000; i++){watched.push({programId:Math.random()});} var ignored = [...watched]; ignored.shuffle(); ignored = ignored.slice(50000, 53000);
Tests:
some
watched.filter(wObj => { return !ignored.some((iObj, ndx) => iObj.programId === wObj.programId); });
some; pop and swap
watched.filter(wObj => !ignored.some((iObj, ndx) => { if (iObj.programId === wObj.programId) { ignored[ndx].programId = ignored.pop().programId; return true; } return false; }) );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
some
some; pop and swap
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
some
4.1 Ops/sec
some; pop and swap
196.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and its components to help explain what's being tested. **Benchmark Definition JSON** The provided JSON defines two benchmark tests: 1. `intersect v2b`: * This is the main test that will be executed by MeasureThat.net. * It involves shuffling an array of objects (`watched`) and then filtering out elements from another array (`ignored`) based on a condition. * The shuffled array is created using the `Array.prototype.shuffle` method, which rearranges the elements in a random order. 2. Two test cases: * `"some"`: This test case compares the execution time of two approaches when filtering the `watched` array without modifying it. * `"some; pop and swap"`: This test case extends the previous one by also checking if there are any duplicates in the `ignored` array that can be swapped with elements from `watched`. **Script Preparation Code** The script preparation code includes two notable components: 1. **Shuffling an array**: The `Array.prototype.shuffle` method is defined to shuffle the elements of an array in place. 2. **Creating and manipulating arrays**: Two arrays are created: `watched` with 100,000 random objects, and `ignored`, which is a copy of `watched` that's shuffled. **Html Preparation Code** The HTML preparation code is empty, indicating that no specific HTML setup is required for this benchmark. **Individual Test Cases** Each test case has a unique name (`"some"` or `"some; pop and swap"`), but they share the same benchmark definition. The differences lie in how duplicates are handled: 1. **No modification**: In the `"some"` test, no modifications are made to the `watched` array when filtering out elements from `ignored`. This is likely a basic comparison to ensure that the built-in filtering algorithm works correctly. 2. **Modifying the watched array**: The `"some; pop and swap"` test case extends the previous one by also checking for duplicates in `ignored` and swapping them with elements from `watched`. This adds complexity to the benchmark, as it introduces an additional operation that may impact performance. **Library: Lodash** The `Array.prototype.shuffle` method is likely a custom implementation or a variant of the popular Lodash library's `shuffle` function. If used, this would provide a convenient and efficient way to shuffle arrays in JavaScript. **Special JS Feature/Syntax** None of the test cases explicitly use any special JavaScript features or syntax that aren't commonly used (e.g., async/await, destructuring, etc.). However, some modern browsers might require additional configuration for the `Array.prototype.shuffle` method to work correctly. **Alternatives** If you'd like to run this benchmark on a different platform or with modified settings, you can consider the following alternatives: 1. **Other JavaScript engines**: MeasureThat.net might support running benchmarks on other JavaScript engines, such as Node.js, V8 (for Android), or SpiderMonkey. 2. **Custom benchmarking frameworks**: You can use alternative benchmarking frameworks like Benchmark.js, JSPerf, or Browser Bench to run similar tests on your own platform. 3. **Modified test cases**: If you want to modify the existing test cases or add new ones, MeasureThat.net provides a flexible API for customizing the benchmark execution. Please keep in mind that modifying or running benchmarks on different platforms might require additional setup and configuration to ensure accurate results.
Related benchmarks:
intersect v2c
intersect v2d
intersect v3b
intersect v3c
Comments
Confirm delete:
Do you really want to delete benchmark?