<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js'></script>
var a = { a: 1, b: 2, c: 3 };
Object.values(a);
var a = { a: 1, b: 2, c: 3 };
_.values(a);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object values | |
_.values |
Test name | Executions per second |
---|---|
Object values | 6248294.0 Ops/sec |
_.values | 4296030.5 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks.
What is being tested?
The provided JSON represents two test cases that compare the performance of the built-in Object.values()
method versus Underscore.js's _.values()
method.
Options compared:
Object.values()
: This method returns an array of values for each enumerable property returned in the specified object._.values()
: This function returns an array containing all the values of an object, similar to the built-in method.Pros and Cons:
Object.values()
: _.values()
:Other considerations:
When choosing between these two options, consider the following factors:
Object.values()
, Underscore.js's _.values()
might be a better choice.Object.values()
method will likely be faster due to its native implementation.Object.values()
method is a better option.Library (Underscore.js):
Underscore.js is a popular JavaScript utility library that provides a collection of functional programming helpers. In this case, its _.values()
function is used as an alternative to the built-in Object.values()
method.
Special JS feature/syntax: None mentioned in the provided benchmark.
To run these tests, you would need to create a new project on MeasureThat.net and paste the provided JSON code. The website will then execute the benchmarks on various devices and browsers, providing raw data that can be analyzed to compare the performance of both methods.
If you're interested in running similar benchmarks or exploring other JavaScript microbenchmarks, I recommend checking out MeasureThat.net's documentation and examples for more information.