@@ -7,14 +7,18 @@ var round = function(num) {
7
7
return Math . round ( ( num * 1000 ) ) / 1000
8
8
}
9
9
10
- var doBenchmark = function ( ) {
10
+ var doBenchmark = function ( cb ) {
11
11
var bench = bencher ( {
12
12
name : 'select large sets' ,
13
13
repeat : 10 ,
14
14
actions : [ {
15
15
name : 'selecting string' ,
16
16
run : function ( next ) {
17
17
var query = client . query ( 'SELECT name FROM items' ) ;
18
+ query . on ( 'error' , function ( er ) {
19
+ console . log ( er ) ; throw er ;
20
+ } ) ;
21
+
18
22
query . on ( 'end' , function ( ) {
19
23
next ( ) ;
20
24
} ) ;
@@ -23,6 +27,10 @@ var doBenchmark = function() {
23
27
name : 'selecting integer' ,
24
28
run : function ( next ) {
25
29
var query = client . query ( 'SELECT count FROM items' ) ;
30
+ query . on ( 'error' , function ( er ) {
31
+ console . log ( er ) ; throw er ;
32
+ } ) ;
33
+
26
34
query . on ( 'end' , function ( ) {
27
35
next ( ) ;
28
36
} )
@@ -31,6 +39,10 @@ var doBenchmark = function() {
31
39
name : 'selecting date' ,
32
40
run : function ( next ) {
33
41
var query = client . query ( 'SELECT created FROM items' ) ;
42
+ query . on ( 'error' , function ( er ) {
43
+ console . log ( er ) ; throw er ;
44
+ } ) ;
45
+
34
46
query . on ( 'end' , function ( ) {
35
47
next ( ) ;
36
48
} )
@@ -44,7 +56,7 @@ var doBenchmark = function() {
44
56
} )
45
57
}
46
58
} , {
47
- name : 'loading all rows into memory' ,
59
+ name : 'loading all rows into memory' ,
48
60
run : function ( next ) {
49
61
var query = client . query ( 'SELECT * FROM items' , next ) ;
50
62
}
@@ -57,6 +69,7 @@ var doBenchmark = function() {
57
69
console . log ( " %s: \n average: %d ms\n total: %d ms" , action . name , round ( action . meanTime ) , round ( action . totalTime ) ) ;
58
70
} )
59
71
client . end ( ) ;
72
+ cb ( ) ;
60
73
} )
61
74
}
62
75
@@ -78,6 +91,35 @@ for(var i = 0; i < count; i++) {
78
91
}
79
92
80
93
client . once ( 'drain' , function ( ) {
81
- console . log ( 'done with insert. executing benchmark.' ) ;
82
- doBenchmark ( ) ;
94
+ console . log ( 'done with insert. executing pure-javascript benchmark.' ) ;
95
+ doBenchmark ( function ( ) {
96
+ var oldclient = client ;
97
+ client = new pg . native . Client ( conString ) ;
98
+ client . on ( 'error' , function ( err ) {
99
+ console . log ( err ) ;
100
+ throw err ;
101
+ } ) ;
102
+
103
+ client . connect ( ) ;
104
+ client . connect ( ) ;
105
+ console . log ( ) ;
106
+ console . log ( "creating temp table" ) ;
107
+ client . query ( "CREATE TEMP TABLE items(name VARCHAR(10), created TIMESTAMPTZ, count INTEGER)" ) ;
108
+ var count = 10000 ;
109
+ console . log ( "inserting %d rows" , count ) ;
110
+ for ( var i = 0 ; i < count ; i ++ ) {
111
+ var query = {
112
+ name : 'insert' ,
113
+ text : "INSERT INTO items(name, created, count) VALUES($1, $2, $3)" ,
114
+ values : [ "item" + i , new Date ( 2010 , 01 , 01 , i , 0 , 0 ) , i ]
115
+ } ;
116
+ client . query ( query ) ;
117
+ }
118
+ client . once ( 'drain' , function ( ) {
119
+ console . log ( "executing native benchmark" ) ;
120
+ doBenchmark ( function ( ) {
121
+ console . log ( "all done" ) ;
122
+ } )
123
+ } )
124
+ } ) ;
83
125
} ) ;
0 commit comments