File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ var pg = require ( __dirname + '/../lib' )
2
+ var bencher = require ( 'bencher' ) ;
3
+ var helper = require ( __dirname + '/../test/test-helper' )
4
+ var conString = helper . connectionString ( )
5
+
6
+ var doBenchmark = function ( ) {
7
+ var bench = bencher ( {
8
+ repeat : 3000 ,
9
+ actions : [ {
10
+ name : 'simple query' ,
11
+ run : function ( next ) {
12
+ var query = client . query ( 'SELECT name FROM person WHERE age > 10' ) ;
13
+ query . on ( 'end' , function ( ) {
14
+ next ( ) ;
15
+ } ) ;
16
+ }
17
+ } , {
18
+ name : 'unnamed prepared statement' ,
19
+ run : function ( next ) {
20
+ var query = client . query ( 'SELECT name FROM person WHERE age > $1' , [ 10 ] ) ;
21
+ query . on ( 'end' , function ( ) {
22
+ next ( ) ;
23
+ } ) ;
24
+ }
25
+ } , {
26
+ name : 'named prepared statement' ,
27
+ run : function ( next ) {
28
+ var config = {
29
+ name : 'get peeps' ,
30
+ text : 'SELECT name FROM person WHERE age > $1' ,
31
+ values : [ 10 ]
32
+ }
33
+ client . query ( config ) . on ( 'end' , function ( ) {
34
+ next ( ) ;
35
+ } ) ;
36
+ }
37
+ } ]
38
+ } ) ;
39
+ bench ( function ( result ) {
40
+ console . log ( ) ;
41
+ result . actions . forEach ( function ( action ) {
42
+ console . log ( "%s -> %d" , action . name , action . meanTime ) ;
43
+ } )
44
+ client . end ( ) ;
45
+ } )
46
+ }
47
+
48
+ var client = new pg . Client ( conString ) ;
49
+ client . connect ( ) ;
50
+ client . connection . once ( 'readyForQuery' , doBenchmark )
You can’t perform that action at this time.
0 commit comments