Skip to content

Instantly share code, notes, and snippets.

@bluedeck
Created January 21, 2018 19:18
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 bluedeck/a2e7159e3afc0b0c3303c7c8e26a1675 to your computer and use it in GitHub Desktop.
Save bluedeck/a2e7159e3afc0b0c3303c7c8e26a1675 to your computer and use it in GitHub Desktop.
if("// testing load speed", true) {
"use strict";
const load_cycles = 10;
let time_s = 0;
let execution = 0;
let done = 0;
const request_uri = "/zh/于斯納爾斯貝里市";
// const request_uri = "/zh/2004年澳门华榕大厦纵火案";
const next_trial = function() {
const xhr = new XMLHttpRequest;
let time_of_admission;
xhr.open("GET", request_uri, true);
xhr.onreadystatechange = () => {
if(xhr.readyState === 4) {
const time_consumed = Date.now() - time_of_admission;
done += 1;
time_s += time_consumed;
console.log(`xhr #${done} is through. w\\ status ${xhr.status}`);
if(done === load_cycles) {
console.log(`${done} trials have been carried out, average time_s is ${time_s / done}.`)
} else {
next_trial();
}
}
};
time_of_admission = Date.now();
execution += 1;
console.log(`xhr #${execution} is initiated.`);
xhr.send();
};
next_trial();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment