Skip to content

Commit

Permalink
pr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pongad committed Oct 12, 2017
1 parent 7a77b6b commit 8bd5f3e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/bigquery/benchmark/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/

const util = require('util');
const async = require('async');
const fs = require('fs');
const util = require('util');
const BigQuery = require('../src/index.js');

if (process.argv.length < 3) {
Expand All @@ -25,7 +26,7 @@ var queryJson = fs.readFileSync(process.argv[2]);
var queries = JSON.parse(queryJson);
var client = BigQuery();

var doQuery = function(queryTxt) {
var doQuery = function(queryTxt, callback) {
var startMilli = new Date().getTime();
var numRows = 0;
var numCols;
Expand All @@ -38,31 +39,31 @@ var doQuery = function(queryTxt) {

client.createQueryStream(query)
.on('error', function(err) {
throw err;
callback(err)
})
.on('data', function(row) {
if (numRows == 0) {
numCols = Object.keys(row).length;
timeFirstByteMilli = new Date().getTime() - startMilli;
} else if (numCols != Object.keys(row).length) {
throw util.format("query %j: wrong number of columns, want %d got %d",
this.end();
callback(util.format("query %j: wrong number of columns, want %d got %d",
queryTxt,
numCols,
Object.keys(row).length);
Object.keys(row).length));
}
numRows++;
})
.on('end', function() {
timeTotalMilli = new Date().getTime() - startMilli;
console.log(util.format("query %j: got %d rows, %d cols, first byte %d sec, total %d sec",
queryTxt,
numRows,
numCols,
timeFirstByteMilli/1000,
timeTotalMilli/1000));
queryTxt,
numRows,
numCols,
timeFirstByteMilli/1000,
timeTotalMilli/1000));
callback(null);
});
}

for (queryTxt of queries) {
doQuery(queryTxt);
}
async.eachSeries(queries, doQuery, err =>{});

0 comments on commit 8bd5f3e

Please sign in to comment.