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
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.2.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script>
var Entity = function() {};
Entity.defaults = {
id: 'ID',
type: 'player',
position: [0, 0],
velocity: [0, 0],
acceleration: [1, 1],
thrust: 10,
angle: Math.PI
};
Entity.merge = function(obj1, obj2) {
var cons = obj1.constructor,
func = cons._mergeFunc, props, p, i;
// Create the merge function if one isn't already defined
if(!func) {
func = '';
// Loop over the first objects default properties and merge obj2's values
if((props = cons.defaults)) {
for(p in props) {
func += 'if(typeof obj2.'+p+' !== "undefined") {' +
'obj.'+p+' = obj2.'+p+';' +
'} ';
}
}
// Create and store the new function
func = cons._mergeFunc = new Function('obj', 'obj2', func);
}
// Run the merge function and return the first object
return func(obj1, obj2), obj1;
};
Entity.mergeLoop = function(obj, obj2) {
var props = obj.constructor.defaults;
for(p in props) {
if(obj2[p] !== undefined) {
obj[p] = obj2[p];
}
}
}
</script>
var obj = new Entity();
var deltaState = {
position: [4,1],
velocity: [1,2],
angle: Math.PI / 2
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Dynamic-method merge |
| ready |
Iterative merge |
| ready |
lodash merge/extend |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.