Skip to content
Browse files

Start mysql clients benchmark

  • Loading branch information...
1 parent 881a971 commit 98e8ccf721281cd66ea158e87311cd17f43ffbe0 @felixge committed Oct 3, 2012
Showing with 45 additions and 0 deletions.
  1. +21 −0 figures/mysql-clients/benchmark/libs/mysql2/index.js
  2. +24 −0 figures/mysql-clients/benchmark/run.js
View
21 figures/mysql-clients/benchmark/libs/mysql2/index.js
@@ -0,0 +1,21 @@
+var mysql = require('mysql');
+
+exports.connect = function(options, cb) {
+ var connection = mysql.createConnection(options);
+ connection.connect(function(err) {
+ cb(err, connection);
+ });
+};
+
+exports.query = function(connection, sql, cb) {
+ var query = connection.query(sql);
+ var rows = 0;
+
+ query
+ .on('result', function(row) {
+ rows++;
+ })
+ .on('end', function() {
+ cb(null, rows);
+ });
+};
View
24 figures/mysql-clients/benchmark/run.js
@@ -0,0 +1,24 @@
+#!/usr/bin/env node
+
+var common = require('../../common');
+var libName = process.argv[2];
+var lib = require('./libs/' + libName);
+
+var options = {
+ user : 'root',
+ password : 'root',
+ database : 'node_mysql_test',
+};
+
+lib.connect(options, function(err, connection) {
+ if (err) throw err;
+
+ common.run(libName, function(cb) {
+ lib.query(connection, 'SELECT * FROM blog_posts', function(err, rows, bytes) {
+ if (err) throw err;
+
+ cb(null, {rows: rows});
+ });
+ });
+});
+

0 comments on commit 98e8ccf

Please sign in to comment.
Something went wrong with that request. Please try again.