Skip to content

Instantly share code, notes, and snippets.

@slWsu
Last active August 29, 2015 14:23
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 slWsu/d4ef864452d09aaf53ae to your computer and use it in GitHub Desktop.
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
/**
* 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