javascript - Use Js to compute function average running time -


i want use js calculate running time of function, seems first time time interval not zero.

var = 0; //var timearray = new array(); //var date1; //var date2; var time = 0; while(i < 5) {     var date1 = new date();     var date2 = new date();     var t = decide_class(attr[i]);     time += (date2.gettime() - date1.gettime());     i++; } 

the attr 2 dimension array , sure decide_class function execute every loop.

you need use high precision timers. following not code.

window["performance"] = window.performance || {}; performance.now = (function() {     return performance.now    ||     performance.webkitnow     ||     performance.msnow         ||     performance.onow          ||     performance.moznow        ||     function() { return new date().gettime(); }; })(); 

instead of using date.gettime() use performance.now();


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -