..
const ka = ['id', 'token', 'family', 'grade', 'hex'];
const k = 'token';
const fl = function(e) {
return e !== k
};
const fna = function() {
return ka.filter(fl)
};
fna();
const ko = {
id: undefined,
token: undefined,
family: undefined,
grade: undefined,
hex: undefined
};
const k = 'token';
const fno = function() {
const {[k]: _, rest} = ko;
return Object.keys(rest);
};
fno();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
fn arr | |
fn obj |
Test name | Executions per second |
---|---|
fn arr | 6716054.5 Ops/sec |
fn obj | 580744.1 Ops/sec |
Let's break down the provided benchmark and explain what's being tested, compared, and some pros and cons of each approach.
Benchmark Overview
The benchmark compares two approaches for filtering data: using Array.prototype.filter()
(in JavaScript) versus object destructuring (const { [k]: _, ...rest } = ko;
).
Options Compared
Library Used
None explicitly mentioned, but Object.keys()
is a built-in JavaScript method.
Special JS Feature/Syntax
The benchmark uses object destructuring (const { [k]: _, ...rest } = ko;
), which is a feature introduced in ECMAScript 2015 (ES6). This syntax allows for concise and readable way to extract properties from an object.
Benchmark Preparation Code
The provided Script Preparation Code
is empty, which means the benchmark uses pre-existing code that's already set up. The Html Preparation Code
is also empty, indicating that the benchmark doesn't require any specific HTML setup.
Other Alternatives
Alternative approaches could include:
Array.prototype.reduce()
to filter an array.However, these alternatives might not be as efficient or concise as the object destructuring approach used in this benchmark.
In summary, the benchmark tests two approaches for filtering data: Array.prototype.filter()
and object destructuring (const { [k]: _, ...rest } = ko;
). While both have their pros and cons, object destructuring appears to be the faster and more concise option.