Created
July 5, 2012 22:05
-
-
Save broofa/3056769 to your computer and use it in GitHub Desktop.
JS-Score Reference Implementation
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
/** | |
* Compute a jsscore for the current JS environment | |
* | |
* @param n (Number) Number of iterations to run. For best results this value | |
* should be selected such that the run time is between 0.1 and | |
* 0.5 seconds. The default (1,000,000) will fall well short of | |
* this on modern devices. This is by design so as to prevent | |
* unintentional CPU contention, but will likely yield inaccurate | |
* results. | |
* | |
* @returns (Number) The JS-Score | |
*/ | |
function jsscore(n) { | |
n = n || 1e6; // Default is to count to 1,000,000 | |
var t = new Date().getTime(); // Start timer | |
for (var i = 0; i < n; i++); // Loop | |
t = new Date().getTime() - t; // Stop timer | |
return Math.log(n / t * 1000) / Math.log(10); // Return log10(iterations/second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment