Instantly share code, notes, and snippets.

Embed
What would you like to do?
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