Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.keys vs lodash _.keys
(version: 3)
Also checking the .map method on the returned array.
Comparing performance of:
_.keys with map vs native with map vs native with forEach
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var value = {a: 30310, b: '100303', c: '3040494'}
Tests:
_.keys with map
_.keys(value).map( function(key){ return {value: _.camelCase(key), label: _.startCase(key)}} )
native with map
Object.keys(value).map( function(key){ return {value: _.camelCase(key), label: _.startCase(key)}} )
native with forEach
var arr = [] Object.keys(value).forEach( function(key){ return arr.push({value: _.camelCase(key), label: _.startCase(key)}) } )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.keys with map
native with map
native with forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1.2 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 17 on iOS 17.1.2
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.keys with map
326776.0 Ops/sec
native with map
326928.2 Ops/sec
native with forEach
311067.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks and explore what's being tested on MeasureThat.net. **What is being tested?** The provided JSON represents three test cases that compare different approaches to extract keys from an object and perform some operations on them. The tests are: 1. Using `Object.keys()` with `map()`. 2. Using Lodash's `_keys()` function with `map()`. 3. Using the native `forEach()` method. **Options compared:** The three test cases compare the performance of different methods to extract keys from an object and perform some operations on them: * **Lodash's _keys()`**: A popular JavaScript utility library that provides a set of functions for functional programming. * **Native Object.keys()**: The built-in `Object.keys()` method in JavaScript, which returns an array of strings containing the property names of an object. * **Native forEach()**: The native `forEach()` method, which applies a provided function to each element in an array. **Pros and Cons:** Here's a brief summary of the pros and cons of each approach: 1. Lodash's `_keys()`: * Pros: + More concise and expressive code. + Easier to use for complex transformations. * Cons: + Adds an external dependency (Lodash). + May have a slight performance overhead due to the additional function call. 2. Native Object.keys(): * Pros: + Built-in and available on all platforms. + No dependencies or overhead. * Cons: + May require more boilerplate code for transformations. 3. Native forEach(): * Pros: + Fast and efficient, since it's a native method. + Can be used with arrays or objects (not just arrays). * Cons: + Less concise and expressive than the other two options. + May require additional logic to handle errors or edge cases. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a set of functions for functional programming. The `_keys()` function returns an array of strings containing the property names of an object, which can then be used as input to further transformations. **Special JS feature: No special features are mentioned in this benchmark.** Now, let's look at the individual test cases: 1. **_.keys() with map**: This test case uses Lodash's `_keys()` function and `map()` to transform the resulting array of keys. 2. **Native with map**: This test case uses the native `Object.keys()` method and `map()` to perform a similar transformation. 3. **Native with forEach**: This test case uses the native `forEach()` method to iterate over an array of keys. **Other alternatives** If you're interested in exploring other approaches, here are some alternatives: * Use other utility libraries like Underscore.js or Ramda, which provide similar functions for working with objects and arrays. * Implement your own solutions using JavaScript's built-in methods and syntax. * Experiment with different transformation strategies, such as using `reduce()` or `filter()` instead of `map()`.
Related benchmarks:
lodash.keys vs Object.keys
lodash.keys vs Object.keys
lodash.keys vs Object.keys
lodash.keys vs Object.keys
Comments
Confirm delete:
Do you really want to delete benchmark?