Search code examples
javascriptweb-worker

Microsecond or at least sub-millisecond timing in a web-worker?


There are libraries for high precision timers in node.js and there is the window.performance.now() for the main thread https://stackoverflow.com/a/21120901/1056563. Is there anything for web-workers (which do not have access to window or the DOM)?


Solution

  • There's a performance property on WorkerGlobalScope. It's not super-widely supported, but then again neither are web workers.

    Specifically, .now() is (apparently) available to web workers, if that's all you need.