wechat wss demo

generate.js 459B

123456789101112131415161718192021222324252627282930
  1. 'use strict'
  2. var mqtt = require('../')
  3. var max = 100000
  4. var i
  5. var buf = Buffer.from('test')
  6. // initialize it
  7. mqtt.generate({
  8. cmd: 'publish',
  9. topic: 'test',
  10. payload: buf
  11. })
  12. var start = Date.now()
  13. var time
  14. for (i = 0; i < max; i++) {
  15. mqtt.generate({
  16. cmd: 'publish',
  17. topic: 'test',
  18. payload: buf
  19. })
  20. }
  21. time = Date.now() - start
  22. console.log('Total time', time)
  23. console.log('Total packets', max)
  24. console.log('Packet/s', max / time * 1000)