Last active
December 16, 2015 01:30
-
-
Save leshikus/5355920 to your computer and use it in GitHub Desktop.
Repetitive network bandwidth check
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> | |
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> | |
<script type="text/javascript"> | |
var relax = 5000; | |
var start = 0; | |
var end = 0; | |
var binfile = ''; | |
function log(message) { | |
var d = document.getElementById('data'); | |
d.innerHTML = d.innerHTML + message + '<br/>'; | |
} | |
function TestDownload() { | |
start = new Date().getTime(); | |
$.ajax({ | |
type: "GET", | |
url: "bigfile.bin?id=" + start, | |
dataType: 'application/octet-stream', | |
success: function(msg) { | |
binfile = msg; | |
end = new Date().getTime(); | |
diff = (end - start) / 1000; | |
bytes = msg.length; | |
speed = (bytes / diff) / 1024 / 1024 * 8; | |
speed = Math.round(speed*100)/100; | |
log('Download ' + speed + ' Mb/s'); | |
}, | |
complete: function(xhr, textStatus) { | |
setTimeout(TestUpload, relax); | |
} | |
}); | |
} | |
function TestUpload() { | |
start = new Date().getTime(); | |
$.ajax({ | |
type: "POST", | |
url: "post.aspx?id=" + start, | |
data: binfile, | |
dataType: 'application/octet-stream', | |
success: function(msg) { | |
end = new Date().getTime(); | |
diff = (end - start) / 1000; | |
bytes = binfile.length; | |
speed = (bytes / diff) / 1024 / 1024 * 8; | |
speed = Math.round(speed*100)/100; | |
log('Upload ' + speed + ' Mb/s'); | |
}, | |
complete: function(xhr, textStatus) { | |
setTimeout(TestDownload, relax); | |
} | |
}); | |
} | |
$(document).ready(function() { | |
TestDownload(); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="data"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment