Created
January 11, 2013 20:51
-
-
Save szmeku/4513863 to your computer and use it in GitHub Desktop.
Extends native 'performance' object with function that measure execution time
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
| (function(w){ | |
| w.performance.measureTime = function(what, times){ | |
| var results = []; | |
| for(var i=0; i<times; i++){ | |
| var start = window.performance.webkitNow(); | |
| what(); | |
| var end = window.performance.webkitNow(); | |
| results.push(end - start); | |
| } | |
| var sum = 0; | |
| for(var i in results){ sum += results[i] } | |
| return sum/results.length; | |
| }; | |
| })(window) | |
| // ======= Example of usage ========== | |
| // executes console.log('dupa') 500 times and returns avarage execution time | |
| performance.measureTime(function(){ | |
| console.log('dupa') | |
| }, 500); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment