Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object values vs _.values vs improved 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 forEach = Function.bind.call(Function.call, Array.prototype.forEach); 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) { const values = []; for(val in O) values.push(val); return values; }; } </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:
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):
**Overview of the Benchmark** The provided benchmark measures the performance of three different approaches to iterate over object values: 1. `_.values(a)` (using Lodash) 2. `Object.values(a)` 3. `Object.valuess(a)` (a polyfill for Object.values) **Lodash Approach (`_.values(a)`)** * Library: Lodash * Purpose: A utility library providing functional programming helpers. * In this case, `_` is an alias for the Lodash namespace. * The `values` function returns a new array containing the values of the given object. Pros: * Well-maintained and widely used library. * Provides a simple and concise way to iterate over object values. Cons: * Adds extra overhead due to the library's existence. * May not be optimized for performance in all scenarios. **Native Approach (`Object.values(a)`)** * Purpose: A built-in method of the Object prototype in JavaScript. * Returns an array containing the property names (keys) of an object. * This approach is specific to modern browsers and environments that support it. Pros: * Fastest and most efficient way to iterate over object values, as it's a native method. * No additional overhead beyond what's required for the browser. Cons: * Not supported in older browsers or environments (e.g., Internet Explorer). * May require polyfills for compatibility. **Polyfill Approach (`Object.valuess(a)`)** * Purpose: A custom implementation of Object.values, providing a fallback for non-supported browsers. * Returns an array containing the values of an object. * This approach is specific to the test environment and may not be suitable for production use. Pros: * Provides compatibility with older browsers or environments. * Can be useful for testing or edge cases. Cons: * Adds extra overhead due to the custom implementation. * May not be optimized for performance in all scenarios. **Comparison** The benchmark measures the execution speed of each approach, and the results indicate that: * The native `Object.values(a)` approach is the fastest. * The Lodash `_values(a)` approach is slightly slower than the native approach. * The polyfill `Object.valuess(a)` approach is the slowest. **Other Alternatives** For iterating over object values, other approaches include: * Using a for...in loop: `for (var key in a) { ... }` * Using Array.prototype.forEach(): `Array.prototype.forEach.call(Object.keys(a), function(key) { ... });` However, these approaches are generally slower than the native `Object.values(a)` method and may have additional overhead due to the use of loops or array operations. It's worth noting that the benchmark's focus is on measuring performance for this specific use case, and other factors like memory usage, cache behavior, or thread safety may be relevant in different scenarios.
Related benchmarks:
lodash vs for-of vs forEach5453
Loop over object: lodash vs Object.entries vs Object.keys vs Object.values
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?