Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Testing lodash methods
(version: 0)
Comparing performance of:
Native vs Lodash.js filter
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var values = { name: "kiss-no" } var prevVal = /(-fi|-no)$/
Tests:
Native
const newObject = _.clone(values); _.each(values, (val, key) => { if (prevVal.test(val)) { newObject[key] = val.replace(prevVal, ""); } else if (typeof val === "object") { newObject[key] = replacePropertyValue(prevVal, val); } }); return newObject;
Lodash.js filter
const newObject = _.clone(values); _.each(values, (val, key) => { if (prevVal.test(val)) { newObject[key] = val.replace(prevVal, ""); } else if (typeof val === "object") { newObject[key] = replacePropertyValue(prevVal, val); } }); return newObject;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash.js filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
4609699.5 Ops/sec
Lodash.js filter
4500848.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmarking JSON and explain what's being tested. **Overview** The test cases are designed to measure the performance of two approaches: native JavaScript implementation and Lodash.js filter. **Lodash library** Lodash is a popular JavaScript utility library that provides various functions for tasks like string manipulation, object manipulation, and more. The `_.clone()` function creates a shallow copy of an object, while `_.each()` iterates over each property of an object. In this benchmark, Lodash.js filter is used to filter out specific strings from the input data. **Benchmarking setup** The benchmark uses a simple JavaScript object `values` as input, containing a single property "name" with value "kiss-no". The test also includes a regular expression pattern `prevVal` that matches the string "-fi" or "-no". **Native implementation** The native implementation creates a new object `newObject` using `const newObject = {...}`. It then iterates over each property of the input data using `_.each()`, applying the following rules: * If a value matches the regular expression pattern, it replaces the matched string with an empty string. * If a value is an object, it calls another function `replacePropertyValue(prevVal, val)` to recursively process its properties. **Lodash.js filter** The Lodash.js filter approach uses the same input data and rules as the native implementation. However, instead of using the `_.each()` method, it employs Lodash's `filter()` function to create a new array containing only the filtered values. **Comparison options** There are two approaches being tested: 1. **Native JavaScript implementation**: This approach tests the performance of the native JavaScript implementation, without relying on any external libraries. 2. **Lodash.js filter**: This approach uses Lodash's `filter()` function to achieve the same filtering result as the native implementation. **Pros and Cons** **Native JavaScript implementation:** Pros: * No dependency on external libraries * May be more efficient since it doesn't involve loading additional code Cons: * Requires manual loop iteration, which can lead to slower performance compared to optimized library functions **Lodash.js filter:** Pros: * Leverages the optimized and tested performance of Lodash's `filter()` function * Easier to maintain and update, as the implementation is provided by the library Cons: * Introduces an additional dependency on the Lodash library * May lead to slower performance due to the overhead of loading and initializing the library **Other considerations** * The benchmark uses a relatively simple input data structure, which may not accurately represent real-world scenarios. * There are no multiple threads or concurrent executions tested, so this is a sequential benchmark. * The benchmark only measures the execution time of the filtering operations, without considering other factors like memory usage or garbage collection overhead. **Alternatives** Other approaches to consider: 1. **V8.js**: This is an open-source implementation of the V8 JavaScript engine, which could be used as an alternative to Lodash's `filter()` function. 2. **Array.prototype.filter()**: Using the built-in `Array.prototype.filter()` method could provide a more efficient filtering solution compared to Lodash's `filter()` function. 3. **Native Web Worker implementation**: Using native Web Workers could allow for concurrent execution of the filtering operations, potentially improving performance.
Related benchmarks:
empty arr
isUndefined
lodash has vs object.hasOwn
lodash noop vs new function
lodash noop vs new function vs optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?