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"
}
];
const final = options.map(ele => ele.description).filter((ele, i, arr) => arr.indexOf(ele) === i);
const final = Array.from(new Set(options.map(({ description }) => description)));
const final = options.map((value) => value.description).filter((value, index, arr) => arr.indexOf(value) === index);
const final = new Set();
for (const iterator of options) {
final.add(iterator.description);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
1 | |
2 | |
3 | |
4 |
Test name | Executions per second |
---|---|
1 | 5807678.5 Ops/sec |
2 | 1074291.0 Ops/sec |
3 | 5686211.5 Ops/sec |
4 | 1201706.5 Ops/sec |
Let's break down the benchmark and its various components.
Benchmark Definition
The benchmark is defined by two parts:
Script Preparation Code: This code snippet defines an array of objects, each representing a test case. Each object has several properties:
description
: a stringgroup_name
: a string (not used in the benchmark)id_equipement
: a number (not used in the benchmark)option_flag
: a booleanpack_content
: an array of numbers (not used in the benchmark)pack_flag
: a booleanprix_ttc
: a number_id
: a unique identifier for each objectHtml 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:
Benchmark Definition
: const final = options.map(ele => ele.description).filter((ele, i, arr) => arr.indexOf(ele) === i);
Benchmark Definition
: const final = Array.from(new Set(options.map(({ description }) => description)));
Benchmark Definition
: const final = options.map((value) => value.description).filter((value, index, arr) => arr.indexOf(value) === index);
Benchmark Definition
: const final = new Set();\r\nfor (const iterator of options) {\r\n final.add(iterator.description);\r\n}
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.