Skip to content

Commit

Permalink
mikro benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Erik Roald committed Jul 11, 2024
1 parent a04ac50 commit e70d6c5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ The CPU had 4 physical cores, and each core supports 2 threads, making a total o
**PostgreSQL**
| | Pool size = 1 | Pool size = 10 |
|--------|---------------|----------------|
| Orange | 24.754s | 24.541s |
| Drizzle| 31.847s | 26.013s |
| Prisma | 49.419s | 33.730s |
| Orange | 24.754 s | 24.541 s |
| Drizzle| 31.847 s | 26.013 s |
| Prisma | 49.419 s | 33.730 s |
| Mikro | 4:07.608 min | 4:12.089 min|
## Steps to Run

The github action will always run remotely on push.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"db:start": "docker run -d -p 15432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres --name my_postgres postgres",
"db:stop": "docker stop my_postgres && docker rm my_postgres",
"init": "cross-env POOLSIZE=1 tsx ./src/initPostgres.ts",
"benchmark": " prisma generate --schema=./src/prisma/schema.prisma && npm run drizzle && npm run orange && npm run prisma",
"benchmark": " prisma generate --schema=./src/prisma/schema.prisma && npm run drizzle && npm run orange && npm run prisma && npm run mikro",
"drizzle": "npm run drizzle:pool1 && npm run drizzle:pool10",
"drizzle:pool1": "npm run init && cross-env POOLSIZE=1 tsx ./src/drizzle/benchmark-pg.ts",
"drizzle:pool10": "npm run init && cross-env POOLSIZE=10 tsx ./src/drizzle/benchmark-pg.ts",
Expand All @@ -25,7 +25,7 @@
"prisma": "npm run prisma:pool1 && npm run prisma:pool10",
"prisma:pool1": "npm run init && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-pg.ts",
"prisma:pool10": "npm run init && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-pg.ts",
"mikro": "npm run mikroorm:pool1 && npm run mikroorm:pool10",
"mikro": "npm run mikro:pool1 && npm run mikro:pool10",
"mikro:pool1": "npm run init && cross-env POOLSIZE=1 tsx ./src/mikro/benchmark-pg.ts",
"mikro:pool10": "npm run init && cross-env POOLSIZE=10 tsx ./src/mikro/benchmark-pg.ts",
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
3 changes: 2 additions & 1 deletion src/drizzle/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as schema from './schema';
import dotenv from 'dotenv';
dotenv.config();
const POOLSIZE = Number.parseInt(process.env.POOLSIZE);
const LOG = process.env.LOG === 'true';

export const connection = postgres(process.env.POSTGRES_URL, { max: POOLSIZE });

export const db = drizzle(connection, {
schema,
logger: false,
logger: LOG,
});

export type db = typeof db;
Expand Down
3 changes: 2 additions & 1 deletion src/mikro/benchmark-pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dotenv.config();
const ITERATIONS = Number.parseInt(process.env.ITERATIONS);
const ROUNDS = Number.parseInt(process.env.ROUNDS);
const POOLSIZE = Number.parseInt(process.env.POOLSIZE)
const LOG = process.env.LOG === 'true';

async function main() {
const orm = await MikroORM.init({
Expand All @@ -31,7 +32,7 @@ async function main() {
min: POOLSIZE,
max: POOLSIZE
},
debug: false,
debug: LOG,
});

await benchmark();
Expand Down
6 changes: 4 additions & 2 deletions src/orange/benchmark-pg.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { exit } from 'node:process';
import pg from './postgres';
import orange from 'orange-orm';

const ITERATIONS = Number.parseInt(process.env.ITERATIONS);
const ROUNDS = Number.parseInt(process.env.ROUNDS);
const POOLSIZE = Number.parseInt(process.env.POOLSIZE)
const LOG = process.env.LOG === 'true';

// for sql logging:
// import orange from 'orange-orm';
// orange.on('query', console.dir)
if (LOG)
orange.on('query', console.dir)

benchmark();

Expand Down
17 changes: 8 additions & 9 deletions src/prisma/benchmark-pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ dotenv.config();
const ITERATIONS = Number.parseInt(process.env.ITERATIONS);
const ROUNDS = Number.parseInt(process.env.ROUNDS);
const POOLSIZE = Number.parseInt(process.env.POOLSIZE);
const LOG = process.env.LOG === 'true';

const prisma = new PrismaClient({
datasources: {
db: {
url: `${process.env.POSTGRES_URL}?connection_limit=${POOLSIZE}`,
},
},
log: [
// { emit: 'event', level: 'query' },
],
log: LOG ? [{ emit: 'event', level: 'query' }] : undefined
});


// prisma.$on('query', (e) => {
// console.log('Query: ' + e.query);
// console.log('Params: ' + e.params);
// console.log('Duration: ' + e.duration + 'ms');
// });
prisma.$on('query', (e) => {
console.log('Query: ' + e.query);
console.log('Params: ' + e.params);
console.log('Duration: ' + e.duration + 'ms');
});

benchmark();

async function benchmark() {
await warmup();
// await warmup();
console.time(`prisma:pool ${POOLSIZE}`);
for (let i = 0; i < ROUNDS; i++) {
await getRowsWithRelations();
Expand Down

0 comments on commit e70d6c5

Please sign in to comment.