File tree Expand file tree Collapse file tree 2 files changed +93
-0
lines changed Expand file tree Collapse file tree 2 files changed +93
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,16 @@ Known incompatibilities:
49
49
50
50
Please submit PR if you require additional compatibility.
51
51
52
+ ## Benchmark
53
+
54
+ A basic [ benchmark] ( ./test/postgres-bridge/benchmark.ts ) shows no overhead as a result of using ` postgres-bridge ` :
55
+
56
+ ```
57
+ pg query: 880ms
58
+ postgres query: 867ms
59
+ postgres-bridge query: 871ms
60
+ ```
61
+
52
62
## Development
53
63
54
64
Running ` postgres-bridge ` tests requires having a local PostgreSQL instance.
Original file line number Diff line number Diff line change
1
+ // This is not really a test, but just a sanity check to ensure
2
+ // that our wrapper does not add substantial overhead to `postgres` implementation.
3
+
4
+ import test from 'ava' ;
5
+ import {
6
+ Pool as PgPool ,
7
+ // @ts -expect-error-next-line pg types not available
8
+ } from 'pg' ;
9
+ import postgres from 'postgres' ;
10
+ import {
11
+ createPostgresBridge ,
12
+ } from '../../src/bridge' ;
13
+
14
+ const PostgresBridge = createPostgresBridge ( postgres ) ;
15
+
16
+ test . serial ( 'pg: benchmark connection.query()' , async ( t ) => {
17
+ const pool = new PgPool ( {
18
+ user : 'postgres' ,
19
+ } ) ;
20
+
21
+ const connection = await pool . connect ( ) ;
22
+
23
+ // warm up
24
+ await connection . query ( 'SELECT 1' ) ;
25
+
26
+ console . time ( 'pg query' ) ;
27
+
28
+ let index = 1_000 ;
29
+
30
+ while ( index -- > 0 ) {
31
+ await connection . query ( 'SELECT 1' ) ;
32
+ }
33
+
34
+ console . timeEnd ( 'pg query' ) ;
35
+
36
+ t . true ( true ) ;
37
+ } ) ;
38
+
39
+ test . serial ( 'postgres: benchmark connection.query()' , async ( t ) => {
40
+ const sql = postgres ( {
41
+ max : 1 ,
42
+ user : 'postgres' ,
43
+ } ) ;
44
+
45
+ // warm up
46
+ await sql `SELECT 1` ;
47
+
48
+ console . time ( 'postgres query' ) ;
49
+
50
+ let index = 1_000 ;
51
+
52
+ while ( index -- > 0 ) {
53
+ await sql `SELECT 1` ;
54
+ }
55
+
56
+ console . timeEnd ( 'postgres query' ) ;
57
+
58
+ t . true ( true ) ;
59
+ } ) ;
60
+
61
+ test . serial ( 'postgres-bridge: benchmark connection.query()' , async ( t ) => {
62
+ const pool = new PostgresBridge ( {
63
+ user : 'postgres' ,
64
+ } ) ;
65
+
66
+ const connection = await pool . connect ( ) ;
67
+
68
+ // warm up
69
+ await connection . query ( 'SELECT 1' ) ;
70
+
71
+ console . time ( 'postgres-bridge query' ) ;
72
+
73
+ let index = 1_000 ;
74
+
75
+ while ( index -- > 0 ) {
76
+ await connection . query ( 'SELECT 1' ) ;
77
+ }
78
+
79
+ console . timeEnd ( 'postgres-bridge query' ) ;
80
+
81
+ t . true ( true ) ;
82
+ } ) ;
83
+
You can’t perform that action at this time.
0 commit comments