-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightbenchmark.min.js
More file actions
2 lines (2 loc) · 1.45 KB
/
lightbenchmark.min.js
File metadata and controls
2 lines (2 loc) · 1.45 KB
1
2
// LightBenchmark.js - A simple and lightweight benchmark tool in native JavaScript. - Version 1.0.1 - MIT License - Copyright (c) 2015 Bertrand Vignaud-Lerouge / n457 - https://github.com/n457
function lightbenchmark(a,c,d){if(a){if("function"===typeof a)c=a,a={};else if(c&&"function"===typeof c)"object"!==typeof a&&(a={},console.info("LightBenchmark.js info : incorrect options. Redefined as an object."));else{console.error("LightBenchmark.js error : missing or incorrect callback function.");return}a.name&&"string"===typeof a.name||(a.name="Default",console.info('LightBenchmark.js info : missing or incorrect name. "'+a.name+'" name given instead.'));if(a.loops)if("number"===typeof a.loops||"string"===typeof a.loops){var b=parseInt(a.loops);if(b)a.loops=b;else switch(a.loops){case "low":a.loops=1E3;break;case "default":a.loops=1E4;break;case "high":a.loops=1E5;break;default:a.loops=1E4,console.info('LightBenchmark.js info : incorrect "loops" value. Default value given instead : 10000.')}}else a.loops=1E4,console.info('LightBenchmark.js info : incorrect "loops" value. Default value given instead : 10000.');else a.loops=1E4,console.info('LightBenchmark.js info : missing "loops" value. Default value given : 10000.');console.info('LightBenchmark.js : "'+a.name+'" code is tested '+a.loops+" times :");console.time(a.name);for(b=0;b<a.loops;b++)c.call(d,b,a);console.timeEnd(a.name);console.log("\n")}else console.info("LightBenchmark.js info : nothing to do.")};