Skip to content

Instantly share code, notes, and snippets.

@srikumarks
Created July 20, 2013 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikumarks/6043702 to your computer and use it in GitHub Desktop.
Save srikumarks/6043702 to your computer and use it in GitHub Desktop.
Quick-n-dirty measurement of the peak callback rate possible in JS.
<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>
@srikumarks
Copy link
Author

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment