Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash fp vs pure js v2
(version: 0)
Comparing performance of:
pure js vs lodash fp vs generator, filter + map vs generator, filterMap vs pure js, reversed
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash-fp/0.10.4/lodash-fp.min.js"></script>
Script Preparation code:
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]; function* map(f, xs) { for (const x of xs) { yield f(x); } } function* filter(f, xs) { for (const x of xs) { if (f(x)) { yield(x); } } } function* filterMap(f, g, xs) { for (const x of xs) { if (f(x)) { yield g(x); } } }
Tests:
pure js
var pure = numbers.filter(num => num % 2 === 0).map(num=> ({ result: num }));
lodash fp
_.flow(_.map(num => ({ result: num })), _.filter(num => num % 2 === 0))(numbers);
generator, filter + map
var pure = [...filter(num => num % 2 === 0, map(num => ({ result: num }), numbers))];
generator, filterMap
var pure = [...filterMap(num => num % 2 === 0, num => ({ result: num }), numbers)];
pure js, reversed
var pure = numbers.map(num=> ({ result: num })).filter(({result}) => result % 2 === 0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
pure js
lodash fp
generator, filter + map
generator, filterMap
pure js, reversed
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The benchmark measures the performance of different ways to filter and map an array of numbers in pure JavaScript, using both generator functions and the Lodash library with its `fp` (functional programming) version. The tests compare the execution speed of these approaches: 1. Pure JavaScript: using built-in Array methods (`filter`, `map`) without any additional libraries. 2. Lodash with `fp`: leveraging the Lodash library's functional programming utilities to simplify and optimize the code. **Options being compared** The benchmark compares four different implementations: 1. **Pure JavaScript**: Using only native JavaScript functions like `Array.prototype.filter()` and `Array.prototype.map()`. 2. **Generator, filter + map**: A custom implementation that uses generator functions (`map` and `filter`) to process the array, then flattens the result using another `filter` function. 3. **Generator, filterMap**: Similar to the previous one, but uses a single `filterMap` function to achieve the same result. 4. **Lodash fp**: Using Lodash's `fp` library to simplify and optimize the code for functional programming. **Pros and Cons of each approach** Here are some general pros and cons of each approach: 1. **Pure JavaScript**: * Pros: Easy to understand, no additional dependencies required. * Cons: May be less efficient due to slower native function calls. 2. **Generator, filter + map**, **Generator, filterMap**: * Pros: Can be more efficient than pure JavaScript due to generator functions' ability to yield values one at a time. * Cons: Require more complex code and may be harder to read for non-experts. 3. **Lodash fp**: * Pros: Provides an optimized, functional programming-friendly implementation that can lead to better performance. * Cons: Requires Lodash library, which adds dependency. **Other considerations** When writing benchmarks like this one, it's essential to consider factors such as: * Input data size and distribution (e.g., random vs. sequential). * System configuration (e.g., CPU architecture, available memory). * Browser or runtime environment specifics (e.g., caching, JIT compilation). **Library and its purpose** In this benchmark, the Lodash library is used for its `fp` utility functions, which provide a more functional programming-friendly API for working with arrays. The `fp` version of these functions is optimized for performance. **Special JS feature or syntax** There are no special JavaScript features or syntaxes being tested in this benchmark, such as async/await, Promises, or ES6+ classes. However, the use of generator functions (`map`, `filter`) does demonstrate a more functional programming-oriented approach to array processing.
Related benchmarks:
Test lodash v2
Array.prototype.map vs Lodash.map
Max value: Lodash vs native array functions
lodash fp vs pure js
Comments
Confirm delete:
Do you really want to delete benchmark?