..
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 ka = ['id', 'token', 'family', 'grade', 'hex'];
const k = 'token';
const fna = function() {
return ka.filter(e => e !== k)
};
fna();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
fn named | |
fn anon |
Test name | Executions per second |
---|---|
fn named | 8256714.5 Ops/sec |
fn anon | 25879180.0 Ops/sec |
Let's break down the provided benchmark JSON and explain what's being tested.
Benchmark Definition
The benchmark defines two test cases:
array filter fn named
: This test case is testing the performance of an array filter function where the filtering condition is defined as a separate, named function (fl
).array filter fn anon
: This test case is testing the performance of an array filter function where the filtering condition is defined inline as an anonymous function.Options being compared
The benchmark is comparing the performance of two approaches:
fl
).e => e !== k
).Pros and Cons
Named Function Approach
Pros:
Cons:
Anonymous Function Approach
Pros:
Cons:
Other Considerations
Library and Special JS Features
In this benchmark, no libraries are explicitly mentioned. However, the use of arrow functions (e => e !== k
) indicates support for a relatively modern JavaScript feature.
Special JS Feature: Arrow Functions
Arrow functions were introduced in ECMAScript 2015 (ES6) as a concise way to define small, single-expression functions. They have since become widely adopted and are supported by most modern browsers and JavaScript engines.
In this benchmark, the use of arrow functions allows for a more compact code snippet, making it easier to read and write inline filter conditions.
Alternatives
If you're looking for alternative approaches or variations on these tests, here are some ideas:
Array.prototype.filter()
, filter()
using a custom iterator, etc.).if-else
statements) or testing with large datasets.These alternatives can help provide a more comprehensive understanding of JavaScript's filtering capabilities and performance characteristics.