Created
March 8, 2020 14:48
-
-
Save davidair/03754554e797b37365a8a7854aaf319e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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