select-100k-blog-rows.js 845 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var common = require('../test/common');
  2. var client = common.createConnection({typeCast: false});
  3. var rowsPerRun = 100000;
  4. client.connect(function(err) {
  5. if (err) throw err;
  6. client.query('USE node_mysql_test', function(err, results) {
  7. if (err) throw err;
  8. selectRows();
  9. });
  10. });
  11. var firstSelect;
  12. var rowCount = 0;
  13. console.error('Benchmarking rows per second in hz:');
  14. function selectRows() {
  15. firstSelect = firstSelect || Date.now();
  16. client.query('SELECT * FROM posts', function(err, rows) {
  17. if (err) throw err;
  18. rowCount += rows.length;
  19. if (rowCount < rowsPerRun) {
  20. selectRows();
  21. return;
  22. }
  23. var duration = (Date.now() - firstSelect) / 1000;
  24. var hz = Math.round(rowCount / duration);
  25. console.log(hz);
  26. rowCount = 0;
  27. firstSelect = null;
  28. selectRows();
  29. });
  30. };