<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
let arrOfObj = {};
new Array(0x10000).fill('omg').map((v,k) => arrOfObj[`key${k}`] = v) // max 65536
const joined = _.filter(arrOfObj, (v, key) => _.includes(['key1', 'key599', 'key2679', 'key60000'], key)).join()
let arrOfObj = {};
new Array(0x10000).fill('omg').map((v,k) => arrOfObj[`key${k}`] = v) // max 65536
const keys = Object.keys(arrOfObj).map((v, k) => ['key1', 'key599', 'key2679', 'key60000'].includes(v)?k:null).filter(x => x)
const joined = Object.keys(arrOfObj).filter((v, k) => keys.includes(k)).join()
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash | |
es6 |
Test name | Executions per second |
---|---|
lodash | 16.5 Ops/sec |
es6 | 17.8 Ops/sec |
Let's break down the provided benchmark and explain what's being tested.
Benchmark Overview
The test case measures the performance of two approaches to join values by columns in an object array: using Lodash's filter
function or writing a custom implementation using only ES6 syntax.
Options Compared
Library: Lodash
Lodash is a popular utility library that provides many functional programming helpers, including filter
and map
. In this benchmark, it's used to filter the object array based on the presence of specific keys. The _.includes
function is used to check if an element exists in an array.
Special JS Feature/ Syntax: None
There are no special JavaScript features or syntaxes being tested in this benchmark. Both implementations rely on standard ES6 features and Lodash's API.
Other Alternatives
If you're interested in exploring alternative approaches, here are a few options:
I hope this explanation helps you understand what's being tested in this benchmark!