Skip to content

Use performance.now() instead of Date.now()... #3483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/pg-native/bench/leaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const loop = function () {

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

const start = Date.now()
const start = performance.now()
async.series(ops, function (err) {
if (err) throw err
console.log(Date.now() - start)
console.log(performance.now() - start)
setImmediate(loop)
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-protocol/src/b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { BufferReader } from './buffer-reader'

const LOOPS = 1000
let count = 0
const start = Date.now()
const start = performance.now()

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

const run = () => {
if (count > LOOPS) {
console.log(Date.now() - start)
console.log(performance.now() - start)
return
}
count++
Expand Down
8 changes: 4 additions & 4 deletions packages/pg/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const exec = async (client, q) => {
}

const bench = async (client, q, time) => {
const start = Date.now()
const start = performance.now()
let count = 0
// eslint-disable-next-line no-constant-condition
while (true) {
await exec(client, q)
count++
if (Date.now() - start > time) {
if (performance.now() - start > time) {
return count
}
}
Expand Down Expand Up @@ -77,9 +77,9 @@ const run = async () => {
values: ['test', Buffer.allocUnsafe(104857600)],
})
console.log('bytea warmup done')
const start = Date.now()
const start = performance.now()
const results = await client.query('SELECT * FROM buf')
const time = Date.now() - start
const time = performance.now() - start
console.log('bytea time:', time, 'ms')
console.log('bytea length:', results.rows[0].data.byteLength, 'bytes')
console.log('on my laptop best so far seen 1407ms and 104857600 bytes')
Expand Down