Permalink
Browse files

Refactor benchmarks spawning, "use strict" everywhere

  • Loading branch information...
1 parent 78fbe0f commit 6a89e5692f93ffcd61ead2f43ce49e62649604a2 @Sannis committed Oct 28, 2012
Showing with 99 additions and 184 deletions.
  1. +1 −1 bin/node-mysql-benchmarks.js
  2. +2 −1 package.json
  3. +2 −33 src/C.js
  4. +2 −33 src/PHP.js
  5. +0 −1 src/config.js
  6. +18 −29 src/db-mysql.js
  7. +29 −0 src/helper.js
  8. +8 −17 src/mariasql.js
  9. +9 −17 src/mysql-libmysqlclient.js
  10. +9 −17 src/mysql-native.js
  11. +9 −17 src/mysql.js
  12. +10 −18 src/odbc.js
@@ -64,7 +64,7 @@ var printProgress = function (msg) {
util.print(msg);
};
if (args.quiet) {
- printProgress = function (msg) {
+ printProgress = function () {
util.print('.');
};
}
View
@@ -34,7 +34,8 @@
, "engines" : { "node" : ">=0.6.x" }
, "dependencies" :
{ "cli-table" : ">=0.2.0"
- , "argparse" : ">=0.1.7"
+ , "argparse":">=0.1.7"
+ , "semver":">=1.1.0"
, "mysql" : "2.0.0-alpha3"
, "mysql-libmysqlclient" : "1.5.1"
, "mysql-native" : "0.4.7"
View
@@ -6,18 +6,8 @@
"use strict";
-// Require modules
-var
- spawn = require('child_process').spawn,
- inspect = require('util').inspect,
- exitEvent = (process.versions.node >= '0.8.0' ? 'close' : 'exit');
-
exports.run = function (callback, cfg) {
- var
- proc,
- args = [],
- key,
- results = '';
+ var args = [], key;
for (key in cfg) {
if (cfg.hasOwnProperty(key)) {
@@ -31,26 +21,5 @@ exports.run = function (callback, cfg) {
}
}
- proc = spawn(__dirname + '/../build/benchmark-cpp', args);
-
- proc.stdout.on('data', function (data) {
- results += data;
- });
-
- proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function (data) {
- if (/^execvp\(\)/.test(data.toString('ascii'))) {
- console.error("Failed to start child process for C++ benchmark.");
- }
- console.error('stderr: ' + inspect(data));
- });
-
- proc.on(exitEvent, function () {
- try {
- results = JSON.parse(results);
- } catch (e) {}
-
- // Finish benchmark
- callback(results);
- });
+ require('./helper').spawnBenchmark(__dirname + '/../build/benchmark-cpp', args, callback, cfg);
};
View
@@ -4,39 +4,8 @@
* See license text in LICENSE file
*/
-// Require modules
-var
- spawn = require('child_process').spawn,
- inspect = require('util').inspect,
- exitEvent = (process.versions.node >= '0.8.0' ? 'close' : 'exit');
+"use strict";
exports.run = function (callback, cfg) {
- var
- proc,
- results = '';
-
- proc = spawn('src/other/benchmark.php');
-
- proc.stdout.on('data', function (data) {
- results += data;
- });
-
- proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function (data) {
- if (/^execvp\(\)/.test(data)) {
- console.error("Failed to start child process for PHP benchmark.");
- }
- console.error('stderr: ' + inspect(data));
- });
-
- proc.on(exitEvent, function (code) {
- try {
- results = JSON.parse(results);
- } catch (e) {}
-
- // Finish benchmark
- callback(results);
- });
-
- proc.stdin.end(JSON.stringify(cfg));
+ require('./helper').spawnBenchmark('src/other/benchmark.php', null, callback, cfg);
};
View
@@ -44,4 +44,3 @@ exports.getConfig = function (factor) {
return cfg;
};
-
View
@@ -4,7 +4,9 @@
* See license text in LICENSE file
*/
-if (!module.parent) {
+"use strict";
+
+function benchmark() {
// Require modules
var
mysql = require('db-mysql'),
@@ -13,21 +15,19 @@ if (!module.parent) {
function fetchAllAsyncBenchmark(results, callback, cfg) {
var
start_time,
- total_time,
- res,
- rows;
+ total_time;
start_time = Date.now();
- conn.query(cfg.select_query).execute(function(error, result) {
+ conn.query(cfg.select_query).execute(function(error) {
if (error) {
console.error(error);
process.exit();
}
total_time = (Date.now() - start_time) / 1000;
- results['selects'] = Math.round(cfg.insert_rows_count / total_time);
+ results.selects = Math.round(cfg.insert_rows_count / total_time);
// Finish benchmark
callback(results);
@@ -45,7 +45,7 @@ if (!module.parent) {
function insertAsync() {
i += 1;
if (i <= cfg.insert_rows_count) {
- conn.query(cfg.insert_query).execute(function(error, result) {
+ conn.query(cfg.insert_query).execute(function(error) {
if (error) {
console.error(error);
process.exit();
@@ -56,7 +56,7 @@ if (!module.parent) {
} else {
total_time = (Date.now() - start_time) / 1000;
- results['inserts'] = Math.round(cfg.insert_rows_count / total_time);
+ results.inserts = Math.round(cfg.insert_rows_count / total_time);
setTimeout(function () {
fetchAllAsyncBenchmark(results, callback, cfg);
@@ -71,7 +71,7 @@ if (!module.parent) {
var
start_time,
total_time,
- i = 0,
+ i,
escaped_string;
start_time = Date.now();
@@ -82,7 +82,7 @@ if (!module.parent) {
total_time = (Date.now() - start_time) / 1000;
- results['escapes'] = Math.round(cfg.escape_count / total_time);
+ results.escapes = Math.round(cfg.escape_count / total_time);
insertAsyncBenchmark(results, callback, cfg);
}
@@ -107,21 +107,21 @@ if (!module.parent) {
conn = this;
- conn.query("DROP TABLE IF EXISTS " + cfg.test_table).execute(function(error, rows) {
+ conn.query("DROP TABLE IF EXISTS " + cfg.test_table).execute(function(error) {
if (error) {
console.error(error);
process.exit();
}
- conn.query(cfg.create_table_query).execute(function(error, rows) {
+ conn.query(cfg.create_table_query).execute(function(error) {
if (error) {
console.error(error);
process.exit();
}
total_time = (Date.now() - start_time) / 1000;
- results['init'] = total_time;
+ results.init = total_time;
escapeBenchmark(results, callback, cfg);
});
@@ -144,21 +144,10 @@ if (!module.parent) {
process.stdin.resume();
}
+if (!module.parent) {
+ benchmark();
+}
+
exports.run = function (callback, cfg) {
- var proc = require('child_process').spawn('node', [__filename]),
- exitEvent = (process.versions.node >= '0.8.0' ? 'close' : 'exit'),
- inspect = require('util').inspect,
- out = '';
- proc.stdout.setEncoding('ascii');
- proc.stdout.on('data', function(data) {
- out += data;
- });
- proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function(data) {
- console.error('stderr: ' + inspect(data));
- });
- proc.on(exitEvent, function() {
- callback(JSON.parse(out));
- });
- proc.stdin.end(JSON.stringify(cfg));
+ require('./helper').spawnBenchmark('node', [__filename], callback, cfg);
};
View
@@ -0,0 +1,29 @@
+/**
+ * Copyright (C) 2012, Oleg Efimov and other contributors
+ *
+ * See license text in LICENSE file
+ */
+
+"use strict";
+
+exports.spawnBenchmark = function (file, args, callback, cfg) {
+ var child = require('child_process').spawn(file, args),
+ exitEvent = (require('semver').gt(process.versions.node, '0.8.0') ? 'close' : 'exit'),
+ out = '';
+
+ child.stdout.setEncoding('ascii');
+ child.stdout.on('data', function (data) {
+ out += data;
+ });
+ child.stderr.setEncoding('utf8');
+ child.stderr.on('data', function (data) {
+ if (/^execvp\(\)/.test(data.toString('ascii'))) {
+ console.error("Failed to start child process for benchmark.");
+ }
+ console.error('stderr: ' + require('util').inspect(data));
+ });
+ child.on(exitEvent, function () {
+ callback(JSON.parse(out));
+ });
+ child.stdin.end(JSON.stringify(cfg));
+};
View
@@ -4,7 +4,9 @@
* See license text in LICENSE file
*/
-if (!module.parent) {
+"use strict";
+
+function benchmark () {
// Require modules
var Client = require('mariasql'),
conn;
@@ -138,21 +140,10 @@ if (!module.parent) {
process.stdin.resume();
}
+if (!module.parent) {
+ benchmark();
+}
+
exports.run = function (callback, cfg) {
- var proc = require('child_process').spawn('node', [__filename]),
- exitEvent = (process.versions.node >= '0.8.0' ? 'close' : 'exit'),
- inspect = require('util').inspect,
- out = '';
- proc.stdout.setEncoding('ascii');
- proc.stdout.on('data', function(data) {
- out += data;
- });
- proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function(data) {
- console.error('stderr: ' + inspect(data));
- });
- proc.on(exitEvent, function() {
- callback(JSON.parse(out));
- });
- proc.stdin.end(JSON.stringify(cfg));
+ require('./helper').spawnBenchmark('node', [__filename], callback, cfg);
};
@@ -3,7 +3,10 @@
*
* See license text in LICENSE file
*/
-if (!module.parent) {
+
+"use strict";
+
+function benchmark() {
// Require modules
var
mysql = require('mysql-libmysqlclient'),
@@ -216,21 +219,10 @@ if (!module.parent) {
process.stdin.resume();
}
+if (!module.parent) {
+ benchmark();
+}
+
exports.run = function (callback, cfg) {
- var proc = require('child_process').spawn('node', [__filename]),
- exitEvent = (process.versions.node >= '0.8.0' ? 'close' : 'exit'),
- inspect = require('util').inspect,
- out = '';
- proc.stdout.setEncoding('ascii');
- proc.stdout.on('data', function(data) {
- out += data;
- });
- proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function(data) {
- console.error('stderr: ' + inspect(data));
- });
- proc.on(exitEvent, function() {
- callback(JSON.parse(out));
- });
- proc.stdin.end(JSON.stringify(cfg));
+ require('./helper').spawnBenchmark('node', [__filename], callback, cfg);
};
View
@@ -3,7 +3,10 @@
*
* See license text in LICENSE file
*/
-if (!module.parent) {
+
+"use strict";
+
+function benchmark() {
// Require modules
var
util = require('util'),
@@ -128,21 +131,10 @@ if (!module.parent) {
process.stdin.resume();
}
+if (!module.parent) {
+ benchmark();
+}
+
exports.run = function (callback, cfg) {
- var proc = require('child_process').spawn('node', [__filename]),
- exitEvent = (process.versions.node >= '0.8.0' ? 'close' : 'exit'),
- inspect = require('util').inspect,
- out = '';
- proc.stdout.setEncoding('ascii');
- proc.stdout.on('data', function(data) {
- out += data;
- });
- proc.stderr.setEncoding('utf8');
- proc.stderr.on('data', function(data) {
- console.error('stderr: ' + inspect(data));
- });
- proc.on(exitEvent, function() {
- callback(JSON.parse(out));
- });
- proc.stdin.end(JSON.stringify(cfg));
+ require('./helper').spawnBenchmark('node', [__filename], callback, cfg);
};
Oops, something went wrong.

0 comments on commit 6a89e56

Please sign in to comment.