Skip to content

Instantly share code, notes, and snippets.

@davidair
Created March 8, 2020 14:48
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 davidair/03754554e797b37365a8a7854aaf319e to your computer and use it in GitHub Desktop.
Save davidair/03754554e797b37365a8a7854aaf319e to your computer and use it in GitHub Desktop.
function fetchCall() {
const Http = new XMLHttpRequest();
const host = window.location.href.substring(0, window.location.href.indexOf(window.location.pathname));
const url = host + "/?file=1mb";
Http.open("GET", url);
Http.send();
Http.onreadystatechange = (e) => {
if (Http.readyState == XMLHttpRequest.DONE) {
document.getElementById("test_result").value = document.getElementById("test_result").value +
"\nReceived data, chunks remaining: " + _chunks;
console.log('Received data, chunks remaining: ' + _chunks);
console.log('Ready state: ' + Http.readyState);
if (_chunks > 0) {
_chunks--;
fetchCall();
}
else {
var endTime = Date.now();
var elapsed_time = endTime - _startTime;
var speed = Math.round((10 * 8) / (elapsed_time / 1000.0));
document.getElementById("test_result").value =
document.getElementById("test_result").value + "\nTime: " + elapsed_time / 1000.0 + "\nSpeed: " + speed + " Mbps";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment