/ Published in: JavaScript
Track how long code takes to load by using a cross browser profiler. Useage :
profiler("start");
//your js
profiler.done("#profiler");
profiler("start");
//your js
profiler.done("#profiler");
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function() { var log = [], index = {}, first, last; // Accumulate seconds for the specified message. // Each message string has its own total seconds. function add( message, seconds ) { var i = index[message]; if( i == null ) { i = log.length; index[message] = i; log[i] = { message:message, seconds:0 }; } log[i].seconds += seconds; } profiler = function( message, since ) { var now = +new Date; add( message, ( now - ( since || last ) ) / 1000 ); return last = +new Date; } profiler.done = function( sel ) { profiler( 'total', first ); $(sel).html( $.map( log, function( item ) { return( item.seconds.toFixed(3) + ': ' + item.message + '<br />'); }).join('') ); }; first = last = +new Date; })();