Created
November 30, 2009 19:41
-
-
Save brianjlandau/245674 to your computer and use it in GitHub Desktop.
A useful function for benchmarking a block of code and displaying the results on the page. *Depends on jQuery
This file contains hidden or 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
// based on methodology developed by PPK: | |
// http://www.quirksmode.org/blog/archives/2009/08/when_to_read_ou.html | |
(function($){ | |
$.benchmark = function(times, result_selector, func){ | |
var startTime = new Date().getTime(); | |
while (times != 0){ | |
func(); | |
times--; | |
} | |
setTimeout(function () { | |
var endTime = new Date().getTime(); | |
var result = (endTime-startTime)/1000; | |
$(result_selector).html(result); | |
},10); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment