bench-fake-server-maria.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var common = require('../test/common');
  2. var Client = require('mariasql');
  3. var connection = new Client();
  4. connection.connect({
  5. host: '127.0.0.1',
  6. port: 3333,
  7. user: 'root',
  8. password: '',
  9. db: 'test'
  10. });
  11. var assert = require('assert');
  12. function benchmarkSelect(numLeft, callback) {
  13. numRows = 0;
  14. var q = connection.query('select 1+1 as qqq');
  15. q.on('result', function(res) {
  16. //console.log("result!");
  17. //console.log(res);
  18. res.on('row', function(r) {
  19. //console.log(r);
  20. numRows++;
  21. });
  22. res.on('end', function() {
  23. if (numLeft > 1)
  24. benchmarkSelect(numLeft-1, callback);
  25. else
  26. callback(numRows);
  27. });
  28. });
  29. }
  30. function benchmarkSelects(n, cb) {
  31. var numSelects = 100;
  32. var start = process.hrtime();
  33. benchmarkSelect(numSelects, function(rowsPerQuery) {
  34. var end = process.hrtime();
  35. var diff = common.hrdiff(start, end);
  36. console.log(' rows: ' + numSelects*1e9/diff + ' results/sec, ' + rowsPerQuery*numSelects*1e9/diff + ' rows/sec');
  37. if (n > 1)
  38. benchmarkSelects(n - 1, cb);
  39. else
  40. cb();
  41. });
  42. }
  43. module.exports = function(done) {
  44. console.log('connected');
  45. var testStart = process.hrtime();
  46. benchmarkSelects(5, function() {
  47. var testEnd = process.hrtime();
  48. console.log('total time: ', common.hrdiff(testStart, testEnd)/1e9 );
  49. connection.end();
  50. if (done)
  51. done();
  52. });
  53. };
  54. connection.on('connect', module.exports);