var someObject = { a: 123, b: 456, c: 789 };
var x = Object.keys(someObject);
var x = Object.entries(someObject);
var x = Object.values(someObject);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object.keys | |
Object.entries | |
Object.values |
Test name | Executions per second |
---|---|
Object.keys | 81908120.0 Ops/sec |
Object.entries | 51517936.0 Ops/sec |
Object.values | 59338352.0 Ops/sec |
What is being tested?
The provided JSON represents a benchmark test case on MeasureThat.net, which compares the performance of three different approaches to iterate over an object's properties: Object.keys()
, Object.entries()
, and Object.values()
.
Options compared:
Pros and Cons:
Object.keys()
, which can be slower for iteration due to the added overhead.Library and its purpose
None of the benchmarked functions use a specific library. They are built-in JavaScript methods for working with objects.
Special JS feature or syntax
None mentioned. The benchmark only tests standard JavaScript features and syntax.
Other alternatives
While not explicitly listed in the benchmark, other ways to iterate over an object's properties include:
for...in
loop: Iterates over property names using a loop.Object.keys()
with a callback function: Allows iterating over property values while still accessing their names.However, these alternatives are not compared in this specific benchmark.
Benchmark preparation code
The provided JavaScript script creates an object named someObject
and assigns it to the variables used in each benchmarked method:
var someObject = { a: 123, b: 456, c: 789 };
This object serves as the test data for the comparison.