Created
November 14, 2014 12:03
-
-
Save Hirurg103/423f878ebe14d0c5911e to your computer and use it in GitHub Desktop.
Benchmark
This file contains 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 benchmark(times, fun) { | |
var accumulatedTime = 0; | |
var meanTime = 0; | |
(function measureOnce(i) { | |
var startTime, endTime; | |
if(i <= 0) { | |
meanTime = accumulatedTime / times; | |
} else { | |
startTime = new Date().getTime(); | |
fun(); | |
endTime = new Date().getTime(); | |
accumulatedTime += (endTime - startTime); | |
measureOnce(i - 1); | |
} | |
})(times); | |
return meanTime; | |
} | |
benchmark(100, function() { | |
$.ajax({ | |
url: 'http://example.com', | |
async: false | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment