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 a custom version of underscore extend without side effects.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js">
</script>
<script>
var slice = Array.prototype.slice,
customExtend = function(obj) {
copy = _.clone(obj);
_.each(slice.call(arguments, 1), function(source) {
for (var prop in source) {
copy[prop] = source[prop];
}
});
return copy;
},
options = {
name: "Dave",
age: 26,
family: {
father: true,
mother: true
}
},
addlOptions = {
occupation: "lumberjack",
education: "phd",
children: {
daughters: ['stephanie', 'amanda'],
sons: ['william']
}
};
var aug = function __aug() {
var args = Array.prototype.slice.call(arguments);
var deep = false;
var org = args.shift();
var type = '';
if (typeof org === 'string' || typeof org === 'boolean') {
type = (org === true)?'deep':org;
org = args.shift();
if (type == 'defaults') {
org = aug({}, org); //clone defaults into new object
type = 'strict';
}
}
for (var i = 0, c = args.length; i < c; i++) {
var prop = args[i];
for (var name in prop) {
if (type == 'deep' && typeof prop[name] === 'object' && typeof org[name] !== 'undefined') {
aug(type, org[name], prop[name]);
} else if (type != 'strict' || (type == 'strict' && typeof org[name] !== 'undefined')) {
org[name] = prop[name];
}
}
}
return org;
};
if (typeof window === 'undefined') module.exports = aug;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
custom underscore extend |
| ready |
underscore extend |
| ready |
jquery deep extend |
| ready |
jquery extend |
| ready |
aug.js |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.