This project aims to compare the performance of two popular Object-Relational Mapping (ORM) libraries, Prisma and TypeORM, specifically in terms of data insertion and reading operations.
Prisma and TypeORM are widely used ORM solutions that simplify database interactions in Node.js applications. This benchmark focuses on evaluating their performance when dealing with data insertion and retrieval tasks.
To run this benchmark, follow these steps:
-
Clone the repository:
git clone git@github.com:farzadso/pg-bench.git
-
Install dependencies:
pnpm install
-
Configure your database connection settings for both Prisma and TypeORM.
-
Run the benchmark script.
pnpm benchmark:prisma
or
pnpm benchmark:typeorm
-
Create the following file:
src/prisma/.env
. -
Update the relevant environment variables based on your database configuration.
-
Add the following content if you're using the docker compose file in the project:
DATABASE_URL=postgresql://benchmark-api-db:benchmark-api-db@localhost:9120/benchmark-api-db
-
Run the following command to establish the link between
schema.prisma
and the.env
file:pnpx prisma generate
-
Run the following command to apply the migrations:
pnpx prisma migrate dev
To change the database configuration edit the values in the src/data-source.ts
file.
The benchmark consists of four main scenarios:
-
Creating many users
-
Creating users in a stress scenario
-
Finding all users
-
Finding users that match a given condition
The benchmark results will be displayed in the console after running each test. It will include metrics such as execution time.
Based on the benchmark results, a comprehensive analysis of Prisma and TypeORM's performance in terms of data insertion and reading operations can be made. This information can help developers make informed decisions when choosing an ORM for their projects.
Contributions are welcome! If you have suggestions or would like to add more tests to this benchmark suite, please feel free to submit a pull request.
This project is licensed under the MIT License.