Joan Miquel Torres 14dc8dd100
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:

https://github.com/brianc/node-postgres/pull/3483#issuecomment-2967119692
2025-06-14 16:38:51 -05:00

51 lines
1.2 KiB
JavaScript

const Client = require('../')
const async = require('async')
const loop = function () {
const client = new Client()
const connect = function (cb) {
client.connect(cb)
}
const simpleQuery = function (cb) {
client.query('SELECT NOW()', cb)
}
const paramsQuery = function (cb) {
client.query('SELECT $1::text as name', ['Brian'], cb)
}
const prepared = function (cb) {
client.prepare('test', 'SELECT $1::text as name', 1, function (err) {
if (err) return cb(err)
client.execute('test', ['Brian'], cb)
})
}
const sync = function (cb) {
client.querySync('SELECT NOW()')
client.querySync('SELECT $1::text as name', ['Brian'])
client.prepareSync('boom', 'SELECT $1::text as name', 1)
client.executeSync('boom', ['Brian'])
setImmediate(cb)
}
const end = function (cb) {
client.end(cb)
}
const ops = [connect, simpleQuery, paramsQuery, prepared, sync, end]
const start = performance.now()
async.series(ops, function (err) {
if (err) throw err
console.log(performance.now() - start)
setImmediate(loop)
})
}
// on my machine this will consume memory up to about 50 megs of ram
// and then stabalize at that point
loop()