..
var ka = ['id', 'token', 'family', 'grade', 'hex'];
var ko = {
id: undefined,
token: undefined,
family: undefined,
grade: undefined,
hex: undefined
};
var k = 'token';
const fl = function(e) {
return e !== k
};
const fna = function(ka) {
return ka.filter(fl)
};
fna(ka);
const fno = function(ko) {
const {[k]: _, rest} = ko;
return Object.keys(rest);
};
fno(ko);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
fn arr | |
fn obj |
Test name | Executions per second |
---|---|
fn arr | 10688915.0 Ops/sec |
fn obj | 6513593.5 Ops/sec |
Let's break down the provided benchmark and its components.
Benchmark Definition
The benchmark definition represents a test case that compares two approaches:
filter()
method to remove elements from an array based on a condition.The benchmark definition provides:
ka
and ko
) for testing<div>
element with an ID (k
) used as a reference in the scriptOptions compared
The two options being compared are:
filter()
.Pros and Cons of each approach:
filter()
for small datasetsLibrary/Script
The script uses two JavaScript features:
filter()
method: a built-in array method that filters elements based on a condition.const { [property]: _, ...rest } = obj;
.Note: The script does not use any external libraries.
Device and Browser
The benchmark was run on:
Other alternatives
Alternative approaches to the two options being compared could include:
forEach()
method instead of filter()
map()
method instead of object destructuring syntax (rest parameter)However, these alternatives might not be suitable for a benchmarking scenario, as they may introduce additional complexity and dependencies.