Skip to content

Commit

Permalink
TypeCast=(true|false) benchmark versions for db-mysql module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sannis committed Oct 29, 2012
1 parent 8a6e214 commit 0a03445
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/config.js
Expand Up @@ -62,10 +62,11 @@ exports.getConfig = function (factor) {
addBenchmark(cfg, "C", false, false);
addBenchmark(cfg, "PHP", false, false);
addBenchmark(cfg, "mariasql", true, false);
addBenchmark(cfg, "db-mysql", false, false);
addBenchmark(cfg, "mysql-libmysqlclient", true, true, "mysql-libmysqlclient");
addBenchmark(cfg, "mysql-libmysqlclient", false, true, "mysql-libmysqlclient *");
addBenchmark(cfg, "odbc", true, true);
addBenchmark(cfg, "db-mysql", true, true, "db-mysql");
addBenchmark(cfg, "db-mysql", true, false, "db-mysql *");
addBenchmark(cfg, "mysql", true, true, "mysql");
addBenchmark(cfg, "mysql", true, false, "mysql *");
addBenchmark(cfg, "mysql-native", true, true);
Expand Down
26 changes: 14 additions & 12 deletions src/db-mysql.js
Expand Up @@ -13,12 +13,12 @@ function benchmark() {
helper = require('./helper'),
conn;

function fetchAllAsyncBenchmark(results, callback, cfg) {
function fetchAllAsyncBenchmark(results, callback, cfg, benchmark) {
var start_hrtime;

start_hrtime = process.hrtime();

conn.query(cfg.select_query).execute(function(error) {
conn.query(cfg.select_query).execute(function(error, rows) {
if (error) {
console.error(error);
process.exit();
Expand All @@ -28,10 +28,10 @@ function benchmark() {

// Finish benchmark
callback(results);
});
}, {cast: benchmark.typeCast});
}

function insertAsyncBenchmark(results, callback, cfg) {
function insertAsyncBenchmark(results, callback, cfg, benchmark) {
var start_hrtime, i = 0;

start_hrtime = process.hrtime();
Expand All @@ -51,15 +51,15 @@ function benchmark() {
results.inserts = Math.round(cfg.insert_rows_count / helper.hrtimeDeltaInSeconds(start_hrtime));

setTimeout(function () {
fetchAllAsyncBenchmark(results, callback, cfg);
fetchAllAsyncBenchmark(results, callback, cfg, benchmark);
}, cfg.delay_before_select);
}
}

insertAsync();
}

function escapeBenchmark(results, callback, cfg) {
function escapeBenchmark(results, callback, cfg, benchmark) {
var
start_hrtime,
i,
Expand All @@ -73,10 +73,10 @@ function benchmark() {

results.escapes = Math.round(cfg.escapes_count / helper.hrtimeDeltaInSeconds(start_hrtime));

insertAsyncBenchmark(results, callback, cfg);
insertAsyncBenchmark(results, callback, cfg, benchmark);
}

function initBenchmark(results, callback, cfg) {
function initBenchmark(results, callback, cfg, benchmark) {
var start_hrtime;

start_hrtime = process.hrtime();
Expand Down Expand Up @@ -108,7 +108,7 @@ function benchmark() {

results.init = helper.roundWithPrecision(helper.hrtimeDeltaInSeconds(start_hrtime), 3);

escapeBenchmark(results, callback, cfg);
escapeBenchmark(results, callback, cfg, benchmark);
});
});
});
Expand All @@ -124,7 +124,9 @@ function benchmark() {
callback = function() {
process.stdout.write(JSON.stringify(results));
};
initBenchmark(results, callback, JSON.parse(cfg));

cfg = JSON.parse(cfg);
initBenchmark(results, callback, cfg, cfg.benchmark);
});
process.stdin.resume();
}
Expand All @@ -133,6 +135,6 @@ if (!module.parent) {
benchmark();
}

exports.run = function (callback, cfg) {
require('./helper').spawnBenchmark('node', [__filename], callback, cfg);
exports.run = function (callback, cfg, benchmark) {
require('./helper').spawnBenchmark('node', [__filename], callback, cfg, benchmark);
};

0 comments on commit 0a03445

Please sign in to comment.