Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map, filter, reduce, intersection comparison
(version: 2)
Comparing performance of:
Map, filter, reduce vs Intersection, union
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
Map, filter, reduce
const offerGameIds = [ { GameId: '4222'}, { GameId: '4208'}, { GameId: '4165'}, { GameId: '4434'}, { GameId: '4200'}, { GameId: '4182'}, { GameId: '4215'}, { GameId: '4114'}, { GameId: '4219'}, { GameId: '4035'}, { GameId: '4070'}, ]; const cmsGameIds = [4222, 4253, 4215, 4141, 4178, 4182, 4135, 4217, 4200, 4194, 4114, 4193, 4219, 4184, 4216, 4142, 4079, 4070, 4035, 4110]; const infoOfferGameIds = offerGameIds.map(item => +item.GameId); const includedGameIds = infoOfferGameIds.filter(id => cmsGameIds.includes(id)); const combinedGameIds = [...includedGameIds, ...cmsGameIds].reduce( (list, item) => (list.includes(item) ? list : [...list, item]), [] );
Intersection, union
const offerGameIds = [ { GameId: '4222'}, { GameId: '4208'}, { GameId: '4165'}, { GameId: '4434'}, { GameId: '4200'}, { GameId: '4182'}, { GameId: '4215'}, { GameId: '4114'}, { GameId: '4219'}, { GameId: '4035'}, { GameId: '4070'}, ]; const cmsGameIds = [4222, 4253, 4215, 4141, 4178, 4182, 4135, 4217, 4200, 4194, 4114, 4193, 4219, 4184, 4216, 4142, 4079, 4070, 4035, 4110]; const infoOfferGameIds = offerGameIds.map(item => +item.GameId); const intersection = _.intersection(infoOfferGameIds, cmsGameIds); const finalArray = _.union(intersection, _.without(cmsGameIds, ...intersection));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map, filter, reduce
Intersection, union
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.40
Browser/OS:
Chrome 117 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map, filter, reduce
775279.2 Ops/sec
Intersection, union
750474.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark tests various aspects of JavaScript code optimization. **Script Preparation Code and HTML Preparation Code** The script preparation code is empty, which means that no custom initialization or setup code is required to run the benchmarks. However, the `Html Preparation Code` includes a reference to the Lodash library, which is used in some test cases. **Individual Test Cases** There are two test cases: 1. **Map, filter, reduce**: This benchmark tests the performance of three operations on an array: mapping, filtering, and reducing (concatenating). The `Benchmark Definition` code creates an array of game IDs, maps them to integers, filters out elements not present in another array, and then reduces the resulting array by concatenating it with the original array. This test case assesses the efficiency of these operations. 2. **Intersection, union**: This benchmark tests the performance of two set operations: intersection (finding common elements) and union (combining unique elements). The `Benchmark Definition` code uses Lodash's `intersection` function to find common game IDs between two arrays. **Options Compared** The benchmarks compare different approaches for achieving a specific result: * Map, filter, reduce vs. reducing and then concatenating: This comparison evaluates the performance of using map and filter with reduce versus combining the operations. * Intersection vs. union (with `_.without`): This comparison tests the efficiency of Lodash's `intersection` function against creating an intersection by excluding unwanted elements. **Pros and Cons** 1. **Map, filter, reduce**: Pros: * More concise code * Can be more readable Cons: * May require more computational resources for filtering and mapping large datasets 2. **Intersection vs. union (with `_.without`)**: Pros of using Lodash's `intersection` function: * Faster execution time * Easier to implement Cons: * Requires the inclusion of the Lodash library **Other Considerations** When optimizing JavaScript code, other factors to consider include: * Data type usage (e.g., numbers vs. strings) * Array size and complexity * Caching and memoization techniques * Minification and compression algorithms **Alternatives** If you're looking for alternatives to MeasureThat.net or want to create your own benchmarking tests, consider the following options: 1. **Benchmark.js**: A popular JavaScript benchmarking library. 2. **Benchmarks**: An open-source JavaScript testing framework. 3. **Google's Benchmark**: A cross-platform benchmarking library developed by Google. 4. **JSPerf**: A simple, online benchmarking tool for JavaScript. These alternatives offer more features and customization options than MeasureThat.net, allowing you to create and run your own custom benchmarks.
Related benchmarks:
Map Comparison
Intersection filter vs lodash intersection
Lodash Intersection vs. ES6 includes
native intersect vs lodash intersection
Lodash, Set, Array comparison
Comments
Confirm delete:
Do you really want to delete benchmark?