<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
<script src='https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)'></script>
var data = Array(10000000).fill({ a: 'a', b: 1 });
_.chain(data).filter(f => f.a === 'a').filter(f => f.b === 1).filter(f => f.b + 1 === 2).map(f => f.a).filter(f => f === 'a').value()
data.filter(f => f.a === 'a' && f.b === 1 && f.b + 1 === 2).map(f => f.a).filter(f => f === 'a')
data.filter(f => f.a === 'a').filter(f => f.b === 1).filter(f => f.b + 1 === 2).map(f => f.a).filter(f => f === 'a')
_.flow(
_.filter(f => f.a === 'a'),
_.filter(f => f.b === 1),
_.filter(f => f.b + 1 === 2),
_.map(f => f.a),
_.filter(f => f === 'a')
)(data)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Chain | |
Native (with &&) | |
Native (without &&) | |
Flow |
Test name | Executions per second |
---|---|
Chain | 1.3 Ops/sec |
Native (with &&) | 1.9 Ops/sec |
Native (without &&) | 1.0 Ops/sec |
Flow | 1.1 Ops/sec |
Overview
MeasureThat.net is a website where users can create and run JavaScript microbenchmarks to compare the performance of different approaches, libraries, and syntax features.
The provided benchmark definition json represents a simple filter-based data processing pipeline using Lodash library functions: chain
, flow
, native (with &&), and native (without &&).
Benchmark Definition
The benchmark consists of four test cases:
_.chain()
method to create a chain of Lodash functions, filtering the data step-by-step.&&
)._.flow()
method to create a sequence of Lodash functions, filtering the data step-by-step.Options Compared
Chain
: vs _.chain()
Native (with &&)
vs &&
operatorNative (without &&)
vs no logical AND operatorFlow
: vs _.flow()
Pros and Cons of Each Approach
Libraries Used
_.chain()
: A method that creates a chain of Lodash functions, allowing for step-by-step filtering and transformation of data._.flow()
: A method that creates a sequence of Lodash functions, also allowing for step-by-step filtering and transformation of data.Special JS Features/Syntax
None mentioned in the benchmark definition.
Other Alternatives
For testing and benchmarking JavaScript code, MeasureThat.net is one of the few platforms offering a straightforward and user-friendly interface. Other alternatives include:
These alternatives may offer more features and flexibility than MeasureThat.net but require more expertise and effort to set up.