fetch response time?
I've tried timing it myself however my time often disagrees with the browser timing, and there's often a noticeable discrepancy between timings on Chrome vs Firefox (from 5-1000ms)
Is there anyway to get the timing from the browser, or achieve better accuracy timing it myself?
Here's my attempt
you can't. processing of JS and browser APIs is determined by the underlying CPU interrupts.
but why does getting accurate figure matter?
instead of Date.now, use performance.now. Though yes they wont be same as there are a lot of variables (cpu frequency, load, pending interrupts, network latency, event loop, etc) in play
performance.now() was actually what I tried first, and saw similar behaviour, so I've continued using Date.now(). Perhaps I'll have to revisit it.
yeah then its your network latency being unpredictable
That can't be it. The browser timing is stable, and consistent with command line pings.
I should clarify, by "browser timing" I'm talking about the the timings displayed in the Networking tab of the developer tools.
oh also javascript timers are made to be a bit inaccurate
Yeah, that's what's got me scratching my head. I read about that in MDN. I just realized that I've had cached disabled, with it enabled I'm still seeing wildly inaccurate timing but in the other direction. I know my ping should be between 50-70ms but with cache enabled, I'm seeing 5-6ms with it disabled I'm seeing 100+
the answer here was use web sockets. So far, waaay better accuracy.
Обсуждают сегодня