@@ -7,14 +7,18 @@ var round = function(num) {
77 return Math . round ( ( num * 1000 ) ) / 1000
88}
99
10- var doBenchmark = function ( ) {
10+ var doBenchmark = function ( cb ) {
1111 var bench = bencher ( {
1212 name : 'select large sets' ,
1313 repeat : 10 ,
1414 actions : [ {
1515 name : 'selecting string' ,
1616 run : function ( next ) {
1717 var query = client . query ( 'SELECT name FROM items' ) ;
18+ query . on ( 'error' , function ( er ) {
19+ console . log ( er ) ; throw er ;
20+ } ) ;
21+
1822 query . on ( 'end' , function ( ) {
1923 next ( ) ;
2024 } ) ;
@@ -23,6 +27,10 @@ var doBenchmark = function() {
2327 name : 'selecting integer' ,
2428 run : function ( next ) {
2529 var query = client . query ( 'SELECT count FROM items' ) ;
30+ query . on ( 'error' , function ( er ) {
31+ console . log ( er ) ; throw er ;
32+ } ) ;
33+
2634 query . on ( 'end' , function ( ) {
2735 next ( ) ;
2836 } )
@@ -31,6 +39,10 @@ var doBenchmark = function() {
3139 name : 'selecting date' ,
3240 run : function ( next ) {
3341 var query = client . query ( 'SELECT created FROM items' ) ;
42+ query . on ( 'error' , function ( er ) {
43+ console . log ( er ) ; throw er ;
44+ } ) ;
45+
3446 query . on ( 'end' , function ( ) {
3547 next ( ) ;
3648 } )
@@ -44,7 +56,7 @@ var doBenchmark = function() {
4456 } )
4557 }
4658 } , {
47- name : 'loading all rows into memory' ,
59+ name : 'loading all rows into memory' ,
4860 run : function ( next ) {
4961 var query = client . query ( 'SELECT * FROM items' , next ) ;
5062 }
@@ -57,6 +69,7 @@ var doBenchmark = function() {
5769 console . log ( " %s: \n average: %d ms\n total: %d ms" , action . name , round ( action . meanTime ) , round ( action . totalTime ) ) ;
5870 } )
5971 client . end ( ) ;
72+ cb ( ) ;
6073 } )
6174}
6275
@@ -78,6 +91,35 @@ for(var i = 0; i < count; i++) {
7891}
7992
8093client . 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+ } ) ;
83125} ) ;
0 commit comments