Mon May 20 12:35:01 2024

PostgreSQL Driver Performance Benchmark Report

Below are the results of testing PostgreSQL client driver implementations. Each client is constrained to run in a single process. Test environment: Linux 6.7.6-arch1-1 (Arch Linux rolling, x86_64) on .

Overall Results

The charts below show the geometric average of all benchmark results.

Individual Benchmarks

1-pg_type.json x10

Test Setup

N/A

Test Query

select typname, typnamespace, typowner, typlen, typbyval, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray from pg_type where typtypmod = $1 and typisdefined = $2
Args: [-1, True]

2-generate_series.json x10

Test Setup

N/A

Test Query

SELECT i FROM generate_series(1, $1) AS i
Args: [1000]

3-large_object.json x10

Test Setup

CREATE TABLE _bytes(b bytea); INSERT INTO _bytes(b) (SELECT repeat('a', 1000)::bytea FROM generate_series(1, 100));

Test Query

SELECT * FROM _bytes
Args: []

6-batch.json x10

Test Setup

CREATE TABLE _test(a int, b int, c int, d text, e real, f int, g text);

Test Query

INSERT INTO _test (a, b, c, d, e, f, g) VALUES ($1, $2, $3, $4, $5, $6, $7);
Args: [{'row': [10, 11, 10, 'TESTTESTTEST', 10.333, 12341234, '123412341234'], 'count': 1000}]

7-oneplusone.json x10

Test Setup

N/A

Test Query

SELECT 1+1
Args: []

Detailed Benchmark Data

Geometric mean 1-pg_type.json x10 2-generate_series.json x10 3-large_object.json x10 6-batch.json x10 7-oneplusone.json x10
golang-libpq
Queries/sec2027.2 1956.2 5429.51 4454.6 27.03 26770.23
Rows/sec291145.34 1195237.85 5429506.97 445459.63 27031.74 26770.23
Min latency0.782ms 0.67ms 0.35ms 0.28ms 222.97ms 0.02ms
Mean latency4.908ms 5.106ms 1.836ms 2.239ms 368.817ms 0.368ms
Max latency21.167ms 17.59ms 8.86ms 10.48ms 467.87ms 5.56ms
Latency variation1.555ms (31.66%) 1.97ms (38.58%) 0.802ms (43.66%) 1.111ms (49.61%) 26.572ms (7.2%) 0.195ms (52.85%)
golang-pgx
Queries/sec5378.86 2642.9 7226.31 10701.47 807.91 27267.58
Rows/sec772498.78 1614809.05 7226314.05 1070146.88 807906.33 27267.58
Min latency0.217ms 0.41ms 0.18ms 0.1ms 6.46ms 0.01ms
Mean latency1.849ms 3.777ms 1.378ms 0.929ms 12.367ms 0.361ms
Max latency17.397ms 16.77ms 6.87ms 5.37ms 764.38ms 3.37ms
Latency variation1.281ms (69.29%) 1.842ms (48.76%) 0.742ms (53.83%) 0.512ms (55.14%) 25.673ms (207.6%) 0.192ms (53.17%)
python-aiopg
Queries/sec983.02 365.37 899.13 2650.52 115.24 9148.08
Rows/sec141180.3 223243.07 899129.46 265052.37 115241.45 9148.08
Min latency3.224ms 4.99ms 2.58ms 2.38ms 66.82ms 0.17ms
Mean latency10.161ms 27.355ms 11.117ms 3.77ms 86.678ms 1.09ms
Max latency34.391ms 52.92ms 26.69ms 19.63ms 128.34ms 13.52ms
Latency variation1.36ms (13.39%) 1.396ms (5.1%) 1.674ms (15.06%) 0.583ms (15.48%) 9.11ms (10.51%) 0.375ms (34.43%)
python-aiopg-tuples
Queries/sec2428.65 2605.72 6070.08 3723.12 123.56 11612.17
Rows/sec348798.08 1592094.52 6070083.03 372312.41 123562.32 11612.17
Min latency1.779ms 2.28ms 0.75ms 1.67ms 52.02ms 0.12ms
Mean latency4.112ms 3.835ms 1.645ms 2.683ms 80.847ms 0.859ms
Max latency17.483ms 9.77ms 9.35ms 11.2ms 131.3ms 12.16ms
Latency variation0.773ms (18.8%) 0.596ms (15.54%) 0.336ms (20.43%) 0.534ms (19.89%) 8.61ms (10.65%) 0.3ms (34.88%)
python-asyncpg
Queries/sec5345.15 4406.3 5946.22 11284.19 742.72 19869.52
Rows/sec767657.25 2692247.19 5946223.09 1128418.83 742716.27 19869.52
Min latency0.473ms 0.87ms 0.49ms 0.16ms 6.95ms 0.05ms
Mean latency1.869ms 2.268ms 1.68ms 0.885ms 13.456ms 0.502ms
Max latency20.122ms 14.69ms 19.29ms 5.67ms 423.38ms 4.85ms
Latency variation1.086ms (58.11%) 0.948ms (41.8%) 1.284ms (76.44%) 0.352ms (39.73%) 15.944ms (118.49%) 0.221ms (44.05%)
python-psycopg3-async
Queries/sec718.51 1085.14 1802.82 1783.1 8.32 6598.34
Rows/sec103189.61 663018.15 1802817.44 178309.65 8319.42 6598.34
Min latency6.885ms 5.61ms 1.9ms 4.0ms 1099.57ms 0.33ms
Mean latency13.905ms 9.21ms 5.543ms 5.604ms 1201.914ms 1.512ms
Max latency34.14ms 25.16ms 19.81ms 13.31ms 1316.63ms 5.31ms
Latency variation2.345ms (16.87%) 1.065ms (11.56%) 1.911ms (34.48%) 1.075ms (19.19%) 60.42ms (5.03%) 0.537ms (35.5%)
python-psqlpy
Queries/sec634.25 407.84 2132.54 649.84 14.19 12797.5
Rows/sec91091.64 249191.73 2132542.61 64984.19 14191.5 12797.5
Min latency2.791ms 3.17ms 0.61ms 2.23ms 654.52ms 0.06ms
Mean latency15.754ms 24.504ms 4.686ms 15.381ms 704.466ms 0.78ms
Max latency49.128ms 73.41ms 27.44ms 39.0ms 755.76ms 4.82ms
Latency variation3.815ms (24.22%) 9.249ms (37.74%) 2.304ms (49.16%) 4.149ms (26.98%) 23.796ms (3.38%) 0.384ms (49.28%)
nodejs-pg-js
Queries/sec706.11 920.08 2764.96 2618.66 2.0 13174.46
Rows/sec103407.94 562168.69 2764964.4 261866.38 2204.96 13174.46
Min latency1.282ms 3.08ms 1.5ms 1.44ms 2.74ms 0.19ms
Mean latency3.487ms 10.86ms 3.615ms 3.817ms 4.532ms 0.759ms
Max latency20.296ms 47.83ms 16.11ms 19.36ms 19.08ms 12.1ms
Latency variation1.107ms (31.76%) 3.308ms (30.45%) 1.204ms (33.31%) 1.483ms (38.86%) 0.805ms (17.76%) 0.35ms (46.16%)
nodejs-ts-postgres
Queries/sec764.95 1294.74 2402.71 4823.04 2.0 8728.45
Rows/sec110866.22 791085.94 2402711.94 482303.94 2093.21 8728.45
Min latency0.848ms 1.89ms 1.08ms 0.48ms 2.36ms 0.19ms
Mean latency3.252ms 7.719ms 4.16ms 2.073ms 4.774ms 1.145ms
Max latency19.305ms 35.64ms 19.22ms 13.39ms 19.82ms 14.75ms
Latency variation1.136ms (34.92%) 2.778ms (35.99%) 1.515ms (36.41%) 0.815ms (39.33%) 1.101ms (23.07%) 0.5ms (43.69%)