Created
August 6, 2017 02:46
-
-
Save scf4/10af79a95d17aa9692a3e63e2baf0e1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { types, Client, Pool } = require('pg'); | |
const Knex = require('knex'); | |
const knex = new Knex({ | |
client: 'pg', | |
connection: 'postgresql://localhost/postgres', | |
}); | |
const benchmark = async (fn, num) => { | |
const start = new Date().getTime(); | |
await Promise.all(Array(num).fill(fn())); | |
const ms = new Date().getTime() - start; | |
console.log(`${num} took ${ms}ms`); | |
}; | |
(async () => { | |
await knex.transaction(async trx => { | |
const fn = () => trx.raw('select 1'); | |
await benchmark(fn, 1000); | |
}); | |
const pool = new Pool({ | |
database: 'postgres', | |
}); | |
const client = await pool.connect(); | |
const fn = () => client.query('select 1'); | |
await benchmark(fn, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try to see result of
select random()
instead ofselect 1
, re-write this code and you'll find that result of both benchmarks are almost the same