const API_EXPECTED_TIME = 1000; const SOME_OTHER_EXPECTED_TIME = 2000; function getImage() { let t0 = performance.now(); fetch(`${GET_IMAGE_API_URL}`).then(response => { const apiRoundtrip = performance.now() - t0; setPerformanceScalar(apiRoundtrip, API_EXPECTED_TIME); // Do stuff }); } function setPerformanceScalar(observed, expected) { this.performanceScalar = observed / expected; // ... // tuck this away in app state, local storage, a global variable, etc } //...