const obj = {
name: 'pepe',
age: 24
};
const secondObj = {
obj,
otraPropiedad: true
};
"use strict"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var obj = { name: 'pepe', age: 24 }; var secondObj = _objectSpread(_objectSpread({}, obj), {}, { otraPropiedad: true });
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
primero | |
segundo |
Test name | Executions per second |
---|---|
primero | 1136431.6 Ops/sec |
segundo | 178672.0 Ops/sec |
Let's break down the provided benchmark and explain what's being tested, compared options, pros and cons, and other considerations.
Benchmark Definition
The benchmark definition is empty, meaning that no custom script preparation code or HTML preparation code is required. This suggests that the focus of the benchmark is on the JavaScript execution itself.
Individual Test Cases
There are two test cases:
Both test cases involve creating an object with properties name
and age
, and then creating a new object by spreading the first object using _objectSpread
. The second test case also adds an additional property otraPropiedad
.
What's being tested?
The primary goal of these benchmarks is to compare the performance of different approaches for creating objects in JavaScript. Specifically:
obj = { name: 'pepe', age: 24 };
)secondObj = _objectSpread(obj, {}, { otraPropiedad: true });
)Comparison of options
There are two main approaches being compared:
const obj = { name: 'pepe', age: 24 }; const secondObj = { ...obj };
const obj = { name: 'pepe', age: 24 }; const secondObj = _objectSpread(obj, {}, { otraPropiedad: true });
Pros and Cons of each approach
Other considerations
The use of _objectSpread
suggests that the benchmark is interested in the performance differences between using spread operators versus bracket notation. The ownKeys
function and _defineProperty
are also being tested, which implies that the benchmark wants to compare the overhead of these functions.
Library usage
The library used here is ES6 (ECMAScript 2015) syntax features, specifically:
{ ...obj }
)_objectSpread
functionownKeys
and _defineProperty
functionsThese libraries are built into modern JavaScript engines and are not specific to MeasureThat.net.
Special JS feature or syntax
The benchmark uses the "use strict" directive at the top of the test cases. This is a valid JavaScript syntax that can affect performance, but it's not typically a significant consideration for microbenchmarks like this one.
Overall, these benchmarks aim to compare the performance of different approaches for creating objects in JavaScript, with a focus on spread operators versus bracket notation.