Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object filter mappingv3
(version: 0)
benchmark comparing the perf of creating a new object by filter out entries
Comparing performance of:
object.entries vs object.keys
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } window.parentObj = {}; for (let i = 0; i < 1000; i++) { window.parentObj[makeid()] = makeid(); }
Tests:
object.entries
const entries = Object.entries(window.parentObj).filter(([k, v], i) => ((i % 2) === 0)); if(entries.length > 0) Object.fromEntries(entries);
object.keys
const keys = Object.keys(window.parentObj).reduce((acc, k, i) => { if ((i % 2) === 0) { acc[k] = window.parentObj[k]; } return acc }, {}); if(Object.keys(keys).length > 0) true;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
object.entries
object.keys
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
object.entries
9764.2 Ops/sec
object.keys
9950.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark, "Object filter mappingv3", compares the performance of two approaches: using `Object.keys()` and `Object.entries()` to filter out entries from an object. **Approach 1: Using Object.keys()** In this approach, the code uses `Object.keys()` to get an array of keys from the `window.parentObj` object. It then uses the `reduce()` method to iterate over the array, creating a new object with only every other key-value pair. Pros: * This approach is more memory-efficient since it doesn't create an intermediate array. * The `reduce()` method can be optimized for performance by the JavaScript engine. Cons: * The use of `reduce()` can lead to slower performance due to the creation of an accumulator object. * The code requires a good understanding of the `reduce()` method and its limitations. **Approach 2: Using Object.entries()** In this approach, the code uses `Object.entries()` to get an array of key-value pairs from the `window.parentObj` object. It then uses the `filter()` method to filter out every other entry from the array. Pros: * This approach is more straightforward and easier to understand than the `reduce()` method. * The use of `filter()` can be optimized for performance by the JavaScript engine. Cons: * This approach creates an intermediate array, which can lead to increased memory usage. * The code requires a good understanding of the `filter()` method and its limitations. **Library: Lodash** In the benchmark definition json, it is mentioned that `window.parentObj` is initialized with some library. Unfortunately, there is no explicit mention of the library name in the provided information. However, based on the context and the use of `makeid()` function, which generates a random ID string, it is likely that Lodash is being used as the underlying library. Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object manipulation, and more. In this case, the `makeid()` function appears to be a custom implementation of the `randomId` function from Lodash. **Other Considerations** The benchmark measures the execution speed of both approaches using the `ExecutionsPerSecond` metric. This metric is calculated by dividing the number of executions by the total time taken to execute the code. A higher value indicates faster performance. Additionally, the benchmark uses a Windows 10 desktop platform with Chrome 125 browser to run the tests. The raw UA string (User Agent) and device platform information can be useful for understanding the environment in which the benchmarks were run. **Alternatives** There are other approaches that could be used to filter out entries from an object, such as: 1. Using a simple `for` loop to iterate over the keys and create a new object with every other key-value pair. 2. Using the `forEach()` method to iterate over the keys and create a new object with every other key-value pair. 3. Using a custom implementation of a filter function using a technique like "bitwise indexing". However, these approaches may not be as efficient or scalable as the two approaches presented in the benchmark.
Related benchmarks:
Object values: Object.entries VS Object.keys VS Object.keys with extra array VS Object.entries without array VS Object values: Object.entries loop for
Object filter mapping
Object filter mappingv2
Object.entries VS Object.keys VS Object.values length check
Comments
Confirm delete:
Do you really want to delete benchmark?