Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Quick transfer
(version: 0)
Object.values() faster? Let's see.
Comparing performance of:
Object.values() vs Lodash vs Custom function
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function extractor(o) { const t = []; for (var k in o) { o['k'] = k; t.push(o[k]); } return t; }
Tests:
Object.values()
var a = {a: {z:1}, b: {z:1}, c: {z:1}, d: {z:1}, e: {z:1}, f: {z:1}, g: {z:1}, h: {z:1}, i: {z:1}, j: {z:1}}; Object.values(a);
Lodash
var a = {a: {z:1}, b: {z:1}, c: {z:1}, d: {z:1}, e: {z:1}, f: {z:1}, g: {z:1}, h: {z:1}, i: {z:1}, j: {z:1}}; _.values(a);
Custom function
var a = {a: {z:1}, b: {z:1}, c: {z:1}, d: {z:1}, e: {z:1}, f: {z:1}, g: {z:1}, h: {z:1}, i: {z:1}, j: {z:1}}; extractor(a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object.values()
Lodash
Custom function
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):
I'll break down the benchmark and its results for you. **Benchmark Definition** The test measures which method is faster: using `Object.values()`, using a custom function `extractor()`, or using the `_.values()` method from the Lodash library. **Options Compared** There are three options compared: 1. **`Object.values()`**: This is a built-in JavaScript method that returns an array of a given object's own enumerable property values. 2. **Custom Function `extractor()`**: This custom function, defined in the "Script Preparation Code" section of the benchmark definition, pushes each key-value pair from the input object into a new array using a for...in loop. 3. **Lodash `.values()` method**: This is a utility function provided by the Lodash library that returns an array of values from an object. **Pros and Cons** * **`Object.values()`**: + Pros: Fast, lightweight, and easy to use. + Cons: May not be as flexible or customizable as other options. * **Custom Function `extractor()`**: + Pros: Customizable, can be optimized for specific use cases, and may be faster than `Object.values()` in certain scenarios. + Cons: Requires more code and effort to write and maintain, can be slower due to the additional function call and loop overhead. * **Lodash `.values()` method**: + Pros: Fast, convenient, and provides additional utility methods for working with arrays. + Cons: Requires including an external library, may add unnecessary overhead. **Library and Its Purpose** The Lodash library is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object transformation, and functional programming. In this benchmark, the `.values()` method from Lodash is used to extract values from an object, but it's not strictly necessary since `Object.values()` can be used instead. **Special JS Feature or Syntax** None mentioned in the provided information. **Other Alternatives** If `Object.values()` is too slow, another alternative could be using a library like Ramda, which provides a similar `.values()` method. Alternatively, a custom implementation using a for...in loop and an array can also be used. Keep in mind that the performance difference between these options may not be significant in all scenarios, and other factors such as memory usage, cache hits, or specific hardware characteristics may also influence the results.
Related benchmarks:
lodash vs nativejs foreach
big lodash vs nativejs foreach
Loop over object: lodash vs Object.entries vs Object.values vs Object.keys (lodash 4.17.15)
lodash mapValues vs vanilla Object.keys foreach vs lodash reduce
Loop over object: lodash.forOwn vs Object.keys().forEach
Comments
Confirm delete:
Do you really want to delete benchmark?