Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Merge array test
(version: 0)
Comparing performance of:
1 vs 2 vs 3 vs 4
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
options = [ { description: "Pack Toit Ouvrant Panoramique Electrique", group_name: "exterieur", id_equipement: 98327, option_flag: 1, pack_content: [98319, 98216], pack_flag: 1, prix_ttc: 1400, _id: "5bae447a09a33a0342646f9b" }, { description: "Rouge Ultimate", group_name: "exterieur", id_equipement: 98301, option_flag: 1, pack_content: [], pack_flag: 0, prix_ttc: 830, _id: "5bae41b209a33a0342646e5e" }, { description: "Roue galette", group_name: "securite", id_equipement: 98265, option_flag: 1, pack_content: [], pack_flag: 0, prix_ttc: 100, _id: "5bae446b09a33a0342646f98" }, { description: "Pack Toit Ouvrant Panoramique Electrique", group_name: "exterieur", id_equipement: 98327, option_flag: 1, pack_content: [98319, 98216], pack_flag: 1, prix_ttc: 1400, _id: "5bae447a09a33a0342646f9b" }, { description: "Rouge Ultimate", group_name: "exterieur", id_equipement: 98301, option_flag: 1, pack_content: [], pack_flag: 0, prix_ttc: 830, _id: "5bae41b209a33a0342646e5e" }, { description: "Roue galette", group_name: "securite", id_equipement: 98265, option_flag: 1, pack_content: [], pack_flag: 0, prix_ttc: 100, _id: "5bae446b09a33a0342646f98" }, { description: "Pack Toit Ouvrant Panoramique Electrique", group_name: "exterieur", id_equipement: 98327, option_flag: 1, pack_content: [98319, 98216], pack_flag: 1, prix_ttc: 1400, _id: "5bae447a09a33a0342646f9b" }, { description: "Rouge Ultimate", group_name: "exterieur", id_equipement: 98301, option_flag: 1, pack_content: [], pack_flag: 0, prix_ttc: 830, _id: "5bae41b209a33a0342646e5e" }, { description: "Roue galette", group_name: "securite", id_equipement: 98265, option_flag: 1, pack_content: [], pack_flag: 0, prix_ttc: 100, _id: "5bae446b09a33a0342646f98" } ];
Tests:
1
const final = options.map(ele => ele.description).filter((ele, i, arr) => arr.indexOf(ele) === i);
2
const final = Array.from(new Set(options.map(({ description }) => description)));
3
const final = options.map((value) => value.description).filter((value, index, arr) => arr.indexOf(value) === index);
4
const final = new Set(); for (const iterator of options) { final.add(iterator.description); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
1
2
3
4
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its various components. **Benchmark Definition** The benchmark is defined by two parts: 1. **Script Preparation Code**: This code snippet defines an array of objects, each representing a test case. Each object has several properties: * `description`: a string * `group_name`: a string (not used in the benchmark) * `id_equipement`: a number (not used in the benchmark) * `option_flag`: a boolean * `pack_content`: an array of numbers (not used in the benchmark) * `pack_flag`: a boolean * `prix_ttc`: a number * `_id`: a unique identifier for each object 2. **Html Preparation Code**: This field is empty, which means that no HTML code is provided for this benchmark. **Individual Test Cases** There are four test cases defined in the benchmark: 1. **Test Case 1**: * `Benchmark Definition`: `const final = options.map(ele => ele.description).filter((ele, i, arr) => arr.indexOf(ele) === i);` * This test case filters an array of objects and returns a new array with only the unique values. 2. **Test Case 2**: * `Benchmark Definition`: `const final = Array.from(new Set(options.map(({ description }) => description)));` * This test case uses a Set to remove duplicates from the array of object descriptions. 3. **Test Case 3**: * `Benchmark Definition`: `const final = options.map((value) => value.description).filter((value, index, arr) => arr.indexOf(value) === index);` * This test case filters an array of objects and returns a new array with only the unique values. 4. **Test Case 4**: * `Benchmark Definition`: `const final = new Set();\r\nfor (const iterator of options) {\r\n final.add(iterator.description);\r\n}` * This test case uses a Set to add each description from the array of objects and returns a new Set with unique values. **Latest Benchmark Result** The latest benchmark result shows the performance of each test case on different devices: | Test Case | ExecutionsPerSecond | | --- | --- | | 1 | 5807678.5 | | 3 | 5686211.5 | | 4 | 1201706.5 | | 2 | 1074291.0 | **Comparison of Test Cases** Based on the benchmark result, Test Case 1 (using `filter` method) is the fastest, followed by Test Case 4 (using a Set). The other two test cases are slower. In general, using a Set to remove duplicates can be more efficient than filtering an array with multiple checks, as it reduces the number of comparisons needed. However, the performance difference may not be significant for small datasets like this one.
Related benchmarks:
Array.map vs reduce
Merge array test 2
array some vs _.some III
Underscore pluck vs map 5
Comments
Confirm delete:
Do you really want to delete benchmark?