Use performance.now() instead of Date.now()... #3483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaced Date.now() for performance.now() (wherever applicable) to improve timing accuracy.
Date.now() is prone to system clock shifts, while performance.now() offers a high-resolution, monotonic clock for consistent, reliable measurements.
Not sure, but it could be involved in timeout issues we experience in VM environment but, anyway, this is the best way to measure time.
Added faliback code to support node prior to 16.0.0 (where perf_hook were not globally exposed by default) and even prior to 8.5.0 (defaulting to Date.now()).
Verified tests passes with node 22.12.0.
Attempted to pass with node prior to 16.0.0 but faced issues due to picked dependencies versions and other code of node_postgres that I guess it haven't been tested with so old node versions.
(I attempted to support at least from 8.0.0 which is declared in engines.node of packages/pg/package.json)
References:
https://nodejs.org/docs/latest-v8.x/api/perf_hooks.html#perf_hooks_performance_now
https://w3c.github.io/hr-time/