Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Custom omit method, with delete
(version: 0)
Comparing performance of:
With Object and Set -> filter vs With Object and delete
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var black = 'black' var green = 'green' var orange = 'orange' var red = 'red' var darkRed = 'darkRed' var blue = 'blue' var lightBlue = 'lightBlue' var navy = 'navy' var basePalette = { black, green, orange, red, darkRed, blue, lightBlue, navy }
Tests:
With Object and Set -> filter
function omit(keys, obj) { exclude = new Set(keys); return Object.fromEntries(Object.entries(obj).filter(e => !exclude.has(e[0]))); } omit(['orange','red', 'darkRed'], basePalette);
With Object and delete
function omit(keys, obj) { var copied = Object.assign({}, obj); for (let n of keys) delete copied[n]; return copied; } omit(['orange','red', 'darkRed'], basePalette);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
With Object and Set -> filter
With Object and delete
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):
Measuring JavaScript performance is an essential task for any developer, especially when optimizing code for different browsers and platforms. **Benchmark Overview** The provided JSON represents two benchmark test cases that measure the performance of the `omit` function in JavaScript. The `omit` function is used to remove specified keys from an object. There are two approaches compared: 1. **With Object and Set -> filter**: This approach uses the `Object.fromEntries` method, which creates a new object by filtering out entries based on a condition (in this case, using a `Set` to exclude certain keys). 2. **With Object and delete**: This approach uses the `delete` operator to remove properties from an object. **Approach 1: With Object and Set -> filter** Pros: * More efficient and concise way of filtering out keys. * Avoids explicit looping over the object's entries. Cons: * May not be supported in older browsers or environments that don't have `Object.fromEntries`. * Can be slower due to the overhead of creating a new set and iterating over its entries. **Approach 2: With Object and delete** Pros: * Widely supported across most browsers and environments. * Can be faster since it uses built-in operator support for deleting properties. Cons: * Less concise than the `filter` approach. * May require more code to handle edge cases or complex filtering logic. **Library Used** In this benchmark, a library called `Set` is used. A `Set` is a collection of unique values that can be stored and iterated over. It's used here to exclude certain keys from the object during filtering. **Special JavaScript Feature/Syntax** There are no special JavaScript features or syntaxes used in these test cases beyond what's standard. **Other Alternatives** If you're looking for alternative approaches to this benchmark, you could consider: * Using a library like Lodash or Underscore.js that provides more comprehensive utility functions, including filtering and mapping operations. * Implementing a custom filtering function using `for...in` loops or other methods. * Using the `map()` method in conjunction with `Object.fromEntries()` to create a new object. Keep in mind that each of these alternatives will introduce additional complexity or overhead, so it's essential to carefully evaluate their performance implications for your specific use case.
Related benchmarks:
LoDash Omit vs Destructured undefined
lodash omit vs vanilla using Object.fromEntries
Test custom omit functions
Plain js vs OmitBy
Comments
Confirm delete:
Do you really want to delete benchmark?