Last active
August 29, 2015 14:23
-
-
Save slWsu/d4ef864452d09aaf53ae to your computer and use it in GitHub Desktop.
Calcule du nombre d’exécution possible d'une fonction javascript pour une seconde
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
/** | |
* Retourne et affiche le nombre d'exécution d'une fonction en une seconde | |
* Zone d'affichage : <div id="affichage"></div> | |
* | |
* @param {function} code a tester | |
* @returns {undefined} | |
*/ | |
function compteExec(fonction) { | |
var tps = 0, start = new Date().getTime(), i = 0; | |
while (tps <= 1000) { | |
i++; | |
fonction(); | |
var tmp = new Date().getTime(); | |
tps = (tmp - start); | |
} | |
document.getElementById("affichage").innerHTML = "Code exécuté " + i + " fois en " + tps / 1000 + " Sec "; | |
} | |
// Comptage !!! | |
compteExec(function () { | |
// Code a tester | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment