all files / lib/zt/ zt.js

64.29% Statements 18/28
64.29% Branches 9/14
50% Functions 3/6
68% Lines 17/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                        70000×                          
//
// zz.js 
// Test microframework
// (c) 2014, Andrey Gershun
 
(function (root, factory) {
    Iif (typeof define === 'function' && define.amd) {
        define([], factory);
    } else Eif (typeof exports === 'object') {
        module.exports = factory();
    } else {
        root.zt = factory();
    }
}(this, function () {
 
function zt(name, times, cb){
	if(arguments.length == 2) {
		cb = times;
		times = zt.times || 10000;
	} else 	Eif(arguments.length == 3) {
		zt.times = times;
	};
	if(!zt.res) zt.res = [];
	var tm = Date.now();
	for(var i=0;i<times;i++) {
		cb();
	};
	zt.res.push({name:name,time: Date.now()-tm})
};
 
zt.log = function() {
	var space = '                                          ';
	var max = 0+Math.max.apply(Math, zt.res.map(function(r){return r.name.length}));
	var head = ('Tests' + space).substr(0,max)+'  Time (ms)';
	console.log(head);
//	console.log(head.map(function(){return '=';}).join());
	zt.res.forEach(function(r){console.log((r.name + space).substr(0,max)+'  '+("       "+r.time).substr(-8));});
	zt.res = [];
}
 
return zt;
}));