Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object reduction with conversion back
(version: 0)
Comparing performance of:
A vs Spread/delete
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = { ...Array.from(Array(10000).keys()) }; var idsToRemove = [1, 47, 420, 421, 69, 1000, 2000, 2001, 8765, 10000];
Tests:
A
Object.fromEntries(Object.entries(data).filter(([k, v]) => { !idsToRemove.includes(k); }));
Spread/delete
var newObjs = { ...data }; idsToRemove.forEach((id) => { delete newObjs[id]; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
A
Spread/delete
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; rv:129.0) Gecko/20100101 Firefox/129.0
Browser/OS:
Firefox 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
A
2860.7 Ops/sec
Spread/delete
1851.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmark in detail. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmark that tests two approaches to reduce an object by removing certain keys and convert it back to its original form. The benchmark is designed to measure the performance of these two approaches, which are compared through multiple executions on various browsers and devices. **Options Compared** Two options are compared in this benchmark: 1. **Approach A: Using Object.fromEntries() with filter()** * This approach filters out keys that should be removed from the object using a callback function and then creates a new object from the remaining key-value pairs. 2. **Approach B: Using spread operator (Spread/delete)** * This approach creates a copy of the original object using the spread operator (`{ ...data }`) and then iterates over an array of IDs to be removed, deleting each corresponding key from the new object. **Pros and Cons** Here are some pros and cons of each approach: 1. **Approach A (Object.fromEntries() with filter())** * Pros: + Efficient use of memory since only a single pass is made over the data. + Less prone to errors due to explicit filtering. * Cons: + May incur additional overhead for creating a new object from the filtered key-value pairs. 2. **Approach B (Spread/delete)** * Pros: + Easy to understand and implement, especially for developers familiar with JavaScript's spread operator. * Cons: + Can be slower due to the overhead of creating multiple temporary objects during iteration. **Other Considerations** 1. **Performance**: The choice between these two approaches may impact performance, depending on the specific use case and data size. 2. **Memory Usage**: Approach A may be more memory-efficient since it only creates a single object, while Approach B involves creating multiple temporary objects during iteration. **Library/Feature Description** There is no explicit library or JavaScript feature being used in these benchmark cases. However, `Object.fromEntries()` was introduced in ECMAScript 2015 (ES6) and provides a convenient way to create an object from an array of key-value pairs. The spread operator (`{ ...data }`) has been part of the language since ES6 as well. **Alternative Approaches** Other approaches to reduce an object by removing certain keys might include: 1. **For loops**: Using a for loop with Object.keys() and bracket notation to access and delete properties. 2. **Lodash library functions**: Utilizing Lodash's `omit` or `pickBy` methods, which provide more concise and expressive ways to filter objects. However, these alternative approaches might incur additional overhead, such as creating temporary objects or using external libraries, which could impact performance.
Related benchmarks:
Data normalization
Map convert
for-in vs object.keys vs object.values for objects perf 5
Object reduction with conversion back (smol)
Comments
Confirm delete:
Do you really want to delete benchmark?