Skip to content

Instantly share code, notes, and snippets.

@champierre
Last active May 15, 2017 01:02
Show Gist options
  • Select an option

  • Save champierre/8bd456fd4df0a3f9aa42c3f1f7031aa7 to your computer and use it in GitHub Desktop.

Select an option

Save champierre/8bd456fd4df0a3f9aa42c3f1f7031aa7 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>SpeedTest</h1>
<div id="speed"></div>
<script>
var imageAddr = "https://machique.st/assets/logo_s.png" + "?n=" + Math.random();
var startTime, endTime;
var downloadSize = 17361;
var download = new Image();
download.onload = function() {
endTime = (new Date()).getTime();
showResults();
}
startTime = (new Date()).getTime();
download.src = imageAddr;
function showResults() {
var duration = (endTime - startTime) / 1000.0;
var bits = downloadSize * 8;
var speedBps = bits/duration;
var speedKbps = speedBps / 1024;
var speedMbps = speedBps / 1024 / 1024;
var el = document.querySelector('#speed')
el.innerHTML = duration + ' s, ' + speedBps.toFixed(0) + ' bps, ' + speedKbps.toFixed(2) + ' Kbps, ' + speedMbps.toFixed(3) + ' Mbps';
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment