Created
July 20, 2013 03:11
-
-
Save srikumarks/6043702 to your computer and use it in GitHub Desktop.
Quick-n-dirty measurement of the peak callback rate possible in JS.
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
<script> | |
// Measuring the rate at which we can get callbacks. | |
// This technique is known, I believe, to yield the | |
// fastest call-me-as-soon-as-you-can time. | |
var start_ms = performance.now(), end_ms; | |
var img = document.createElement('img'); | |
var count = 0, N = 10000; | |
function callback() { | |
count++; | |
if (count === N) { | |
end_ms = performance.now(); | |
document.write('Calls per second = ' + Math.round((1000 * N / (end_ms - start_ms)))); | |
} else { | |
img.onerror = callback; | |
img.src = 'nonsense'; | |
} | |
} | |
img.onerror = callback; | |
img.src = 'nonsense'; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few trial runs -
Chrome gives around 2300 calls per second
Firefox is impressive with about 5500 calls per second
Safari offers around 1200 calls per second (using Date.now instead of performance.now)
Now, this may not indicate the maximum rate at which the browser can raise events, but this figure is better than being in the dark I guess. (edit: This would be a lower bound on the rate at which browsers can raise events.)