test-prepare-and-close.js 700 B

123456789101112131415161718192021222324252627
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. var max = 500;
  5. var start = process.hrtime();
  6. function prepare(i) {
  7. connection.prepare('select 1+' + i, function(err, stmt) {
  8. stmt.close();
  9. if (!err) {
  10. if (i > max) {
  11. var end = process.hrtime(start);
  12. var ns = end[0]*1e9+end[1];
  13. console.log(max*1e9/ns + ' prepares/sec');
  14. return connection.end();
  15. }
  16. setTimeout(function() {prepare(i+1)}, 2);
  17. return;
  18. }
  19. assert(0, 'Error in prepare!');
  20. });
  21. }
  22. connection.query('SET GLOBAL max_prepared_stmt_count=10', function(err) {
  23. if (err) throw err;
  24. prepare(1);
  25. });