Last active
September 22, 2020 07:19
-
-
Save neruthes/44ee6b4be2b8b2cabe01774ec1c695f5 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
| const pingHttps = function(limit) { | |
| let totalTimes = -1; | |
| const myPingData = []; | |
| const analyzeData = function (inputDataArr) { | |
| console.log('Raw Ping Data:'); | |
| console.log(myPingData); | |
| var roundTripTimeArr = inputDataArr.map(x => x.end - x.begin); | |
| var avgRoundTripTime = roundTripTimeArr.reduce((a, b) => a + b) / roundTripTimeArr.length; | |
| console.log(`Tested ${roundTripTimeArr.length} times. Average round trip time: ${avgRoundTripTime} ms.`); | |
| }; | |
| const microPing = function (limit) { | |
| totalTimes += 1; | |
| var currentSeq = totalTimes + 0; | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('GET', location.href + '?t=' + Date.now()); | |
| xhr.onload = (function (currentSeq) { | |
| return function () { | |
| myPingData[currentSeq].end = Date.now(); | |
| if (totalTimes < limit - 1) { | |
| microPing(limit); | |
| } else { | |
| analyzeData(myPingData); | |
| }; | |
| }; | |
| })(currentSeq); | |
| xhr.send(); | |
| myPingData[currentSeq] = { | |
| begin: Date.now() | |
| }; | |
| }; | |
| microPing(limit); | |
| }; | |
| pingHttps(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment