Skip to content

Commit 14dc8dd

Browse files
authored
Use performance.now() instead of Date.now()... (#3483)
* Use performance.now() instead of Date.now()... * Wherever applicable (measuring performance, not time). * Failback to support node < 16.0.0 (perf_hook not globally exposed) * Failback to Date.now() for node < 8.5.0 ✔ Tests passed with node > 16.0.0 (22.12.0) ✕ Couldn't pass with node prior 16.0.0 but not due to this changes. https://nodejs.org/docs/latest-v8.x/api/perf_hooks.html#perf_hooks_performance_now https://w3c.github.io/hr-time/ * Yarn prettier * More lint fixes. * Removed polyfill code for node <16 They are no longer supported: #3483 (comment)
1 parent 8608fb8 commit 14dc8dd

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/pg-native/bench/leaks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ const loop = function () {
3737

3838
const ops = [connect, simpleQuery, paramsQuery, prepared, sync, end]
3939

40-
const start = Date.now()
40+
const start = performance.now()
4141
async.series(ops, function (err) {
4242
if (err) throw err
43-
console.log(Date.now() - start)
43+
console.log(performance.now() - start)
4444
setImmediate(loop)
4545
})
4646
}

packages/pg-protocol/src/b.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { BufferReader } from './buffer-reader'
44

55
const LOOPS = 1000
66
let count = 0
7-
const start = Date.now()
7+
const start = performance.now()
88

99
const reader = new BufferReader()
1010
const buffer = Buffer.from([33, 33, 33, 33, 33, 33, 33, 0])
1111

1212
const run = () => {
1313
if (count > LOOPS) {
14-
console.log(Date.now() - start)
14+
console.log(performance.now() - start)
1515
return
1616
}
1717
count++

packages/pg/bench.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ const exec = async (client, q) => {
2323
}
2424

2525
const bench = async (client, q, time) => {
26-
const start = Date.now()
26+
const start = performance.now()
2727
let count = 0
2828
// eslint-disable-next-line no-constant-condition
2929
while (true) {
3030
await exec(client, q)
3131
count++
32-
if (Date.now() - start > time) {
32+
if (performance.now() - start > time) {
3333
return count
3434
}
3535
}
@@ -77,9 +77,9 @@ const run = async () => {
7777
values: ['test', Buffer.allocUnsafe(104857600)],
7878
})
7979
console.log('bytea warmup done')
80-
const start = Date.now()
80+
const start = performance.now()
8181
const results = await client.query('SELECT * FROM buf')
82-
const time = Date.now() - start
82+
const time = performance.now() - start
8383
console.log('bytea time:', time, 'ms')
8484
console.log('bytea length:', results.rows[0].data.byteLength, 'bytes')
8585
console.log('on my laptop best so far seen 1407ms and 104857600 bytes')

0 commit comments

Comments
 (0)