Merge Test #jsbench #jsperf (http://jsbench.github.io/#97fdf75b8411c5d528b033114e35d73f) #jsbench #jsperf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Merge Test #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> | |
<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
(function (factory) { | |
if (typeof Benchmark !== "undefined") { | |
factory(Benchmark); | |
} else { | |
factory(require("benchmark")); | |
} | |
})(function (Benchmark) { | |
var suite = new Benchmark.Suite; | |
Benchmark.prototype.setup = function () { | |
var defaults = { | |
version: "4.1.6", | |
createDate: "04/05/2011 08:56AM", | |
modifiedDate: "03/04/2016 12:24AM", | |
debug: false, | |
isActive: false, | |
throw_alerts: false, | |
preferred_API: "findAPI", // findAPI, findSCORM12, findSCORM2004 | |
prefix: "SCOBotBase", | |
exit_type: "suspend", // suspend, finish, or "" (undetermined) | |
success_status: "unknown", // passed, failed, unknown | |
use_standalone: true, // false if you don't want it to fail over locally | |
standalone: false, // flag | |
completion_status: "incomplete", // default completed, incomplete, unknown | |
time_type: "UTC", // See GMT (pre 1972) vs UTC (post 1972) Time http://www.timeanddate.com/time/gmt-utc-time.html | |
cmi: null, | |
latency_arr: [] | |
}, | |
settings = { | |
exit_type: "finish", | |
success_status: "success", | |
use_standalone: false, | |
time_type: "GMT" | |
}; | |
}; | |
suite.add("function extend1 () {", function () { | |
function extend1 () { | |
var i = 1, | |
args = arguments, | |
olen = args.length, | |
key; | |
while (i < olen) { | |
for (key in args[i]) { | |
if (args[i].hasOwnProperty(key)) { | |
args[0][key] = args[i][key]; | |
} | |
} | |
i += 1; | |
} | |
return args[0]; | |
} | |
var result1 = extend1(defaults, settings); | |
//console.log(result1); | |
}); | |
suite.add("function extend2 (to, from) {", function () { | |
function extend2 (to, from) { | |
for (n in from) { | |
if (typeof to[n] != 'object') { | |
to[n] = from[n]; | |
} else if (typeof from[n] == 'object') { | |
to[n] = extend2(to[n], from[n]); | |
} | |
} | |
return to; | |
} | |
var result2 = extend2(defaults, settings); | |
//console.log(result2); | |
}); | |
suite.add("function extend3(obj1, obj2) {", function () { | |
function extend3(obj1, obj2) { | |
for (var p in obj2) { | |
try { | |
// Property in destination object set; update its value. | |
if ( obj2[p].constructor==Object ) { | |
obj1[p] = MergeRecursive(obj1[p], obj2[p]); | |
} else { | |
obj1[p] = obj2[p]; | |
} | |
} catch(e) { | |
// Property in destination object not set; create it and set its value. | |
obj1[p] = obj2[p]; | |
} | |
} | |
return obj1; | |
} | |
var result3 = extend3(defaults, settings); | |
//console.log(result3); | |
}); | |
suite.on("cycle", function (evt) { | |
console.log(" - " + evt.target); | |
}); | |
suite.on("complete", function (evt) { | |
console.log(new Array(30).join("-")); | |
var results = evt.currentTarget.sort(function (a, b) { | |
return b.hz - a.hz; | |
}); | |
results.forEach(function (item) { | |
console.log((idx + 1) + ". " + item); | |
}); | |
}); | |
console.log("Merge Test #jsbench #jsperf"); | |
console.log(new Array(30).join("-")); | |
suite.run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment