Created
June 26, 2012 15:52
-
-
Save filmaj/2996625 to your computer and use it in GitHub Desktop.
cordova bench web assets
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name=viewport content=width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no> | |
</head> | |
<body> | |
<h1>Cordova how fast are you?</h1> | |
<script src="cordova-1.9.0rc1.js"></script> | |
<script type="text/javascript"> | |
document.addEventListener("deviceready", ready, false); | |
var firstReturn = false, | |
returns = 0, | |
iterations = 2000, | |
startTime, | |
endTime, | |
runTime, | |
messages = []; | |
function logReturn() { | |
returns++; | |
if (!firstReturn) { | |
firstReturn = new Date | |
messages.push('earliest return was ' + (firstReturn - startTime) + 'ms after start time, ' + (firstReturn - runTime) + 'ms after run time') | |
} | |
if (returns == iterations) { | |
endTime = new Date | |
var span = (endTime - firstReturn) | |
messages.push(iterations + ' returns completed over ' + span + 'ms, ' + (span/iterations) + ' per ms') | |
messages.forEach(function(msg) { | |
console.log(msg); | |
}); | |
} | |
return; | |
} | |
function ready() { | |
messages.push('starting test'); | |
var hz, | |
period, | |
counter = iterations; | |
var win = function(echoed) { | |
logReturn(); | |
} | |
var fail = function(err) { | |
logReturn(); | |
} | |
startTime = new Date | |
do { | |
cordova.exec(win, fail, 'VelocityBench', 'echo', ['hello world eh']); | |
} while (--counter); | |
runTime = new Date; | |
// convert ms to seconds | |
var totalTime = (runTime - startTime) / 1000; | |
// period → how long per operation | |
period = totalTime / iterations; | |
// hz → the number of operations per second | |
hz = 1 / period; | |
messages.push(iterations + ' runs in ' + totalTime + ' seconds') | |
messages.push(hz + 'hz') | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment