Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object values vs _.values vs polyfill
(version: 0)
Comparing performance of:
_.values vs Object values vs proposal-object-values-entries/polyfill.js
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script> <script> const reduce = Function.bind.call(Function.call, Array.prototype.reduce); const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable); const concat = Function.bind.call(Function.call, Array.prototype.concat); const keys = Reflect.ownKeys; if (!Object.valuess) { Object.valuess = function values(O) { return reduce(keys(O), (v, k) => concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), []); }; } </script>
Script Preparation code:
var a = { a: 1, b: 2, c: 3};
Tests:
_.values
_.values(a);
Object values
Object.values(a);
proposal-object-values-entries/polyfill.js
Object.valuess(a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.values
Object values
proposal-object-values-entries/polyfill.js
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; rv:131.0) Gecko/20100101 Firefox/131.0
Browser/OS:
Firefox 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.values
5316624.0 Ops/sec
Object values
23070326.0 Ops/sec
proposal-object-values-entries/polyfill.js
1504251.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark compares the execution performance of three different approaches to access object values: 1. **_.values(a)**: This approach uses the Lodash library's `values` function to retrieve the object values. 2. **Object.values(a)**: This is a built-in JavaScript method that returns an array containing the property values of the specified object. 3. **proposal-object-values-entries/polyfill.js**: This is a polyfill for the proposed `Object.valuess` and `Object.entries` methods, which are not yet supported in all browsers. **Options Compared** The benchmark compares the execution performance of these three approaches on different JavaScript engines. The options being compared are: * **_.values(a)**: Uses Lodash's `values` function. * **Object.values(a)**: Built-in JavaScript method for accessing object values. * **proposal-object-values-entries/polyfill.js**: Polyfill for proposed `Object.valuess` and `Object.entries` methods. **Pros and Cons of Different Approaches** 1. **_.values(a)**: * Pros: * Widely supported by Lodash and other libraries. * Easy to use and understand. * Cons: * May introduce additional dependencies (Lodash). * Might be slower due to the added overhead of a library function call. 2. **Object.values(a)**: * Pros: * Built-in JavaScript method, eliminating dependency on external libraries. * Can be faster since it's a native method with optimized implementation. * Cons: * Not yet supported in older browsers or environments without recent updates. 3. **proposal-object-values-entries/polyfill.js**: * Pros: * Provides a unified way to access object values across different browsers and engines. * Can be useful for projects targeting older browsers or environments. * Cons: * May introduce additional dependencies (polyfills). * Might be slower due to the added overhead of a polyfill. **Library - Lodash** Lodash is a popular JavaScript library that provides a set of high-order functions and utility methods. The `values` function in this benchmark is used to retrieve an array of values from an object. Lodash's `values` function leverages the `Object.values` method, which was introduced in ECMAScript 2017. **Special JS Feature - Spread Operator (Rest Parameter)** The spread operator (`...`) is a syntax feature introduced in ECMAScript 2015. It allows for creating new arrays or objects by spreading existing ones. In this benchmark, the `Function.bind.call(Function.call, Array.prototype.reduce)` syntax uses a rest parameter to handle variable numbers of arguments. This is not related to the main comparison but demonstrates advanced JavaScript features. **Alternatives** Other alternatives for accessing object values include: * **Object.keys(a)**: Returns an array of keys (property names) in the specified object. * **for...in**: Iterates over the properties of an object using a `for` loop. * **Array.prototype.forEach()**: Iterates over the property values of an object using a callback function. These alternatives might be useful depending on the specific use case, but they may not offer the same performance benefits as native methods like `Object.values(a)`.
Related benchmarks:
Object values vs _.values vs improved polyfill
lodash vs for-of vs forEach5453
lodash mapValues vs vanilla Object.keys foreach vs lodash reduce
Object values vs _.values vs polyfill vs map polyfill
Comments
Confirm delete:
Do you really want to delete benchmark?