This repository benchmarks the performance of inserting and querying 10 million rows in PostgreSQL using UUIDv4 and UUIDv7 as primary keys. It measures insertion time to help determine which version of UUID performs better under realistic database workloads.
What This Does
-
Generates 10 million rows of random data with UUIDv4 and UUIDv7 as primary keys.
-
Inserts them into two separate PostgreSQL tables:
uuid_v4_test
anduuid_v7_test
. -
Measures and prints time taken to generate and insert UUIDs
- Clone the Repo
git clone https://github.com/your-username/uuid-benchmark.git
cd uuid-benchmark
- Create the Tables in PostgreSQL
Make sure you have a local PostgreSQL instance running and a database named uuid_benchmark. Create the required tables:
CREATE TABLE uuid_v4_test (
id UUID PRIMARY KEY,
payload TEXT
);
CREATE TABLE uuid_v7_test (
id UUID PRIMARY KEY,
payload TEXT
);
- Run the Benchmark
go run main.go
This will:
-
Generate UUIDv4 and UUIDv7 datasets
-
Insert them into the database in batches of 10,000
-
Print time taken for each insertion