Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Get object values
(version: 0)
Comparing performance of:
Object.values vs Lodash vs For loop vs Return array
Created:
6 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 Preparation code:
var a = {'a': 1, 'b': 2} var b = [1, 2]
Tests:
Object.values
Object.values(a)
Lodash
_.values(a)
For loop
var c = [] for(const key in a) { c.push(a[key]) } c
Return array
b
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Object.values
Lodash
For loop
Return array
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):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is defined by two types of code: script preparation code and HTML preparation code. The script preparation code is executed once, before running the actual benchmark tests. In this case, it creates an object `a` with properties `'a'` and `'b'`, and an array `b`. This setup ensures that all test cases have access to these variables. The HTML preparation code includes a link to the Lodash library, which is used in one of the test cases. **Individual Test Cases** There are four test cases: 1. **Object.values**: Tests the built-in JavaScript method `Object.values()` on object `a`. 2. **Lodash**: Tests the `_values()` function from the Lodash library. 3. **For loop**: Tests an alternative implementation using a for loop to iterate over object `a` and push its values into an array `c`. 4. **Return array**: Tests that simply returning the array `b` is fast enough. **Options Compared** The test cases compare different approaches: * Built-in JavaScript method (`Object.values()`) vs. Lodash library (`_values()`). * For loop implementation vs. direct function call (returning an array). **Pros and Cons of Each Approach** 1. **Built-in JavaScript method (`Object.values()`) vs. Lodash library (`_values()`)**: * Built-in: No external dependency, easier to understand, but might be slower due to language overhead. * Lodash: Faster, more efficient, and widely used, but requires an additional library import. 2. **For loop implementation vs. direct function call**: * For loop: More readable, familiar syntax, but potentially slower due to iteration overhead. * Direct function call: Faster, more concise, but less readable. **Other Considerations** The benchmark also measures the impact of device platform (Desktop) and operating system (Mac OS X 10.14.6). This suggests that the test is not just focused on JavaScript performance but also on browser and hardware-specific aspects. As for special JS features or syntax, none are mentioned in this specific benchmark. **Alternatives** Other approaches to achieve similar results could include: * Using `for...in` instead of `Object.values()` for a more traditional for loop implementation. * Utilizing other libraries like Moment.js or Underscore.js for array manipulation. * Implementing custom iteration logic using `forEach()` or `map()`. * Using a different data structure, such as an object with numerical properties. Keep in mind that these alternatives might not provide the same level of performance as the built-in JavaScript method or optimized libraries like Lodash.
Related benchmarks:
circleTest
Lodash values vs Object.values
Get values from object
Lodash vs Object.keys
Lodash vs Native maxBy
Comments
Confirm delete:
Do you really want to delete benchmark?