-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Performance: pg VS postgres.js VS Bun.SQL #3391
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
Comments
Actually, I'm benchmarking few days 3 packages in production on real data, with non-trivial raw sql:
I follow not only the number of Postman benchmark, but also from logs of execution time of each query, and also from tracing of DataDog. The only question now is - either I want to deal with We use Prisma in general... but I must have max performance... |
@spaiz if you want use literal string as query try https://www.npmjs.com/package/sql-template-tag import sql from "sql-template-tag";
import pg from "pg";
const id = 10;
pg.query( sql`SELECT * FROM books WHERE id = ${id}` ); |
@cesco69 Yeah, spent half a day for that. It uses esm, I'm using commonjs on node 20... at the end, finally successfully adopted it. Needed to upgrade to nodejs 22 which supports commonjs and esm modules to be used together. |
TL;TR: pg seems fast!
Hi, I've made a small benchmark to compare this library against others that claim to be the fastest: Postgres.js and Bun.SQL.
Inspired by some online benchmarks, here’s the first test:
package.json
index.js
run with
And here are the results:
At first glance, pg seems very slow, but that’s not actually the case. The reason is that Bun and Postgres.js automatically cache prepared statements by default, whereas pg requires setting the name parameter to enable prepared statement caching. If we update the benchmark like this:
pg
actually becomes faster thanpostgres.js
:pg is still slower than Bun.SQL, but that’s mainly because Bun is written in Rust! Maybe compared to pg-native, Bun would lose, but it's not possible to run this benchmark since pg-native only works on Node.js.
I've also run a benchmark with more test cases:
pg
seem very fastIn the "parallel" bench the gap with Bun increases because Bun has the "pipeline mode" active (but also Postgres.js has it)
The text was updated successfully, but these errors were encountered: