window.performance.now method and
For instance, we can write:
const ms = window.performance.timing.navigationStart + window.performance.now() const ns = ms / 0.001 console.log(ns)
to get the current timestamp in nanoseconds.
window.performance.timing.navigationStart returns the timestamp in milliseconds when we run the code.
window.performance.now returns the number of nanoseconds since the code has run.
Then to convert the timestamp in milliseconds to nanoseconds, we divide
ms by 0.001.