Skip to content

Instantly share code, notes, and snippets.

@Hirurg103
Created November 14, 2014 12:03
Show Gist options
  • Save Hirurg103/423f878ebe14d0c5911e to your computer and use it in GitHub Desktop.
Save Hirurg103/423f878ebe14d0c5911e to your computer and use it in GitHub Desktop.
Benchmark
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