Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
omit function testing
(version: 5)
Comparing performance of:
current vs new vs new delete vs new delete (assign) vs new delete (mutates)
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
obj = { name: 'Frank', age: '12', 1: 1, 2: 2, 3: 3 } keys = ['age', 1, 3]
Tests:
current
const newObj = {}; const keysToInclude = Object.keys(obj).filter(key => !keys.includes(key)); for (const key of keysToInclude) { newObj[key] = obj[key]; }
new
const result = {}; for (const [key, value] of Object.entries(obj)) { if (!keys.includes(key)) { result[key] = value; } }
new delete
newObj = { ...obj }; keys.forEach(key => delete newObj[key])
new delete (assign)
const newObj = Object.assign({}, obj) keys.forEach(key => delete newObj[key])
new delete (mutates)
keys.forEach(key => delete obj[key])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
current
new
new delete
new delete (assign)
new delete (mutates)
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 provided JSON and individual test cases to understand what is being tested, compared, and analyzed. **Benchmark Context** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The goal is to compare the performance of different approaches for a specific problem or function. **Test Case: Omit Function Testing** The benchmark tests four different ways to omit certain keys from an object: 1. **New Delete (Mutates)**: `keys.forEach(key => delete obj[key])` 2. **New Delete (Assign)**: `const newObj = Object.assign({}, obj); keys.forEach(key => delete newObj[key])` 3. **Current**: This approach is not specified in the JSON, but it's mentioned in the test name. 4. **New**: This approach uses `Object.entries(obj)` and iterates over the entries to filter out unwanted keys. **Options Compared** The benchmark compares four different approaches: * `New Delete (Mutates)`: Directly deletes properties from the original object (`obj`). * `New Delete (Assign)`: Creates a new object by assigning an empty object to `Object.assign()`, and then deletes properties from this new object. * **Current**: This approach is not explicitly defined, but it's likely using some variation of the other approaches. **Pros and Cons** Here are some pros and cons of each approach: * **New Delete (Mutates)**: * Pros: Efficient use of iteration and no need to create a new object. * Cons: Modifies the original object, which might have performance implications for certain applications. * **New Delete (Assign)**: * Pros: Creates a new object, which can be beneficial for immutability or performance in some cases. * Cons: Requires an extra step and might incur additional overhead due to object creation. * **Current** (Assuming it's similar to `New`): * Pros: Uses iteration and filtering, which can be efficient for large datasets. * Cons: Might be less efficient than direct deletion or assignment-based approaches. **Library Usage** None of the test cases use any external libraries beyond JavaScript's built-in `Object.keys()`, `Object.entries()`, and `delete` statements.
Related benchmarks:
object.keys map vs for in
checks if object has any key - Object.keys vs for key in
checks if object has any key - Object.keys vs for key in 2
omit vs delete 1234
omit vs delete 123444
Comments
Confirm delete:
Do you really want to delete benchmark?