Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.keys vs object.keys
(version: 1)
Comparing performance of:
_.keys vs Object.keys
Created:
8 years ago
by:
Registered User
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 o = {} for(var i = 0; i < 101; i++) { o[i] = new Date() }
Tests:
_.keys
_.keys(o)
Object.keys
Object.keys(o)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.keys
Object.keys
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.keys
1558789.2 Ops/sec
Object.keys
1567539.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The benchmark in question compares the performance of two approaches: using Lodash's `_keys` function versus the built-in `Object.keys()` method. **Benchmark Definition JSON** The benchmark definition JSON contains information about the test: * **Name**: The name of the benchmark, which is "_keys vs object.keys". * **Description**: An empty description, indicating that no detailed explanation is provided. * **Script Preparation Code**: A script that creates an array `o` with 101 elements, each containing a new Date object. This script is used to warm up the JavaScript engine before running the benchmark. * **Html Preparation Code**: A link to include Lodash's JavaScript library in the test environment. **Individual Test Cases** The benchmark consists of two individual test cases: 1. **_.keys(o)**: This test case calls the `_keys` function from Lodash on the `o` array, which is created by the script preparation code. 2. **Object.keys(o)**: This test case calls the built-in `Object.keys()` method on the `o` array. **Options Compared** The benchmark compares two options: * **Lodash's `_keys` function**: A utility function provided by Lodash that returns an array of keys from a given object. * **Built-in `Object.keys()` method**: A native JavaScript method that returns an array of property names in an object. **Pros and Cons of Each Approach** Here are the pros and cons of each approach: * **Lodash's `_keys` function**: + Pros: Efficient and well-optimized, providing a consistent result across browsers. + Cons: Requires including Lodash in the test environment, which may add overhead. * **Built-in `Object.keys()` method**: + Pros: Built-in to JavaScript, eliminating the need for additional libraries or overhead. + Cons: May not be as efficient or consistent as Lodash's `_keys` function, depending on browser implementation. **Other Considerations** When choosing between these two approaches, consider the following factors: * **Breadth of support**: If you want to ensure compatibility with older browsers or environments that don't support Lodash, using `Object.keys()` might be a safer choice. * **Performance**: If you prioritize performance and can include Lodash in your test environment, `_keys` function might provide better results. **Library Used** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as string manipulation, array manipulation, and more. In this benchmark, the `_keys` function from Lodash is used to extract an array of keys from the `o` object. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. Both test cases rely on standard JavaScript constructs and built-in methods.
Related benchmarks:
lodash.keys vs Object.keys
lodash.keys vs Object.keys
lodash.keys vs Object.keys
Lodash forOwn vs Native keys + forEach 1000 keys
Comments
Confirm delete:
Do you really want to delete benchmark?