Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
babel objectWithoutProperties
(version: 0)
vs native spread
Comparing performance of:
objectWithoutProperties vs native spread
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
Tests:
objectWithoutProperties
const x = { a: 1, b: 2, c: 'foo', d: 'bar' } const y = objectWithoutProperties(x, ['a', 'b'])
native spread
const x = { a: 1, b: 2, c: 'foo', d: 'bar' } const { a, b, ...y } = x
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
objectWithoutProperties
native spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
objectWithoutProperties
14382944.0 Ops/sec
native spread
21596850.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its options. **Benchmark Definition** The benchmark is comparing two approaches to create a new object without some of its properties: 1. `objectWithoutProperties`: This is a function that takes an object as input, along with an array of property names to exclude from the resulting object. 2. `native spread` (also known as the "spread operator"): This uses the syntax `{ ...obj }` to create a new object by spreading some properties from another object. **Options Compared** The benchmark is comparing these two options: * `objectWithoutProperties`: This approach explicitly defines a function to create the resulting object. It has the advantage of being explicit and controlled, but it can be less efficient than the native spread operator due to the overhead of function calls. * `native spread`: This approach uses a syntax that is commonly used in JavaScript for creating new objects from existing ones. It is typically more efficient than the explicitly defined function because it avoids the overhead of function calls. **Pros and Cons** * `objectWithoutProperties`: + Pros: Explicit, controlled, and potentially more readable code. + Cons: Can be less efficient due to the overhead of function calls. * `native spread`: + Pros: More concise and efficient code. + Cons: Less explicit and potentially less readable code. **Library** In this benchmark, there is no external library being used. The `objectWithoutProperties` function is defined inline in the benchmark definition, while the native spread operator is a built-in JavaScript syntax. **Special JS Features/Syntax** The benchmark uses the "spread operator" syntax, which is a feature of modern JavaScript. This syntax allows you to create a new object by spreading some properties from an existing object. It was introduced in ECMAScript 2018 (ES2020) and has since become widely supported in most browsers. **Alternatives** If you wanted to implement `objectWithoutProperties` without using the native spread operator, you could use other approaches, such as: * Using a library like Lodash or Underscore.js, which provide a utility function for removing properties from objects. * Implementing your own recursive function to remove properties from an object. However, these alternatives would likely have different performance characteristics and might not be as efficient as the native spread operator.
Related benchmarks:
Object creation
JavaScript spread vs Object.assign performance vs native spread
isContextEqual vs fast-deep-equal
Strict isContextEqual vs fast-deep-equal
Comments
Confirm delete:
Do you really want to delete benchmark?