jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Testing Object.keys vs for-in. I see that SlickGrid uses objects with indexed keys rather than arrays. Confused....
var X = function() {
this.x = 1;
this.y = 4;
};
var data = [
{foo: 'bar', bar: null, d: 3, f: 20, g: 30},
{bar: null, 12312312: 30},
new X(),
{bar: null, 12312312: 30},
new X(),
{foo: 'bar', bar: null, d: 3, f: 20, g: 30}
];
var ownProp = Object.prototype.hasOwnProperty;
function _assign_forin(to, from) {
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
}
function _assign_keys(to, from) {
var keys = Object.keys(from);
for (var i = 0; i < keys.length; i++) {
to[keys[i]] = from[keys[i]];
}
}
function assign_forin(target, sources) {
if (target == null) {
throw new TypeError('Object.assign target cannot be null or undefined');
}
var to = Object(target);
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
var nextSource = arguments[nextIndex];
if (nextSource == null) {
continue;
}
var from = Object(nextSource);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
}
return to;
}
function assign_forin_separate_function(target, sources) {
if (target == null) {
throw new TypeError('Object.assign target cannot be null or undefined');
}
var to = Object(target);
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
var nextSource = arguments[nextIndex];
if (nextSource == null) {
continue;
}
_assign_forin(to, Object(nextSource));
}
return to;
}
function assign_keys(target, sources) {
if (target == null) {
throw new TypeError('Object.assign target cannot be null or undefined');
}
var to = Object(target);
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
var nextSource = arguments[nextIndex];
if (nextSource == null) {
continue;
}
var from = Object(nextSource);
var keys = Object.keys(from);
for (var i = 0; i < keys.length; i++) {
to[keys[i]] = from[keys[i]];
}
}
return to;
}
function assign_keys_separate_function(target, sources) {
if (target == null) {
throw new TypeError('Object.assign target cannot be null or undefined');
}
var to = Object(target);
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
var nextSource = arguments[nextIndex];
if (nextSource == null) {
continue;
}
_assign_keys(to, Object(nextSource));
}
return to;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
assign_forin |
| ready |
assign_forin_separate_function |
| ready |
assign_keys |
| ready |
assign_keys_separate_function |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.