You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

  1. /*!
  2. * ws: a node.js websocket client
  3. * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Benchmark dependencies.
  8. */
  9. var benchmark = require('benchmark')
  10. , Sender = require('../').Sender
  11. , suite = new benchmark.Suite('Sender');
  12. require('tinycolor');
  13. require('./util');
  14. /**
  15. * Setup sender.
  16. */
  17. suite.on('start', function () {
  18. sender = new Sender();
  19. sender._socket = { write: function() {} };
  20. });
  21. suite.on('cycle', function () {
  22. sender = new Sender();
  23. sender._socket = { write: function() {} };
  24. });
  25. /**
  26. * Benchmarks
  27. */
  28. framePacket = new Buffer(200*1024);
  29. framePacket.fill(99);
  30. suite.add('frameAndSend, unmasked (200 kB)', function () {
  31. sender.frameAndSend(0x2, framePacket, true, false);
  32. });
  33. suite.add('frameAndSend, masked (200 kB)', function () {
  34. sender.frameAndSend(0x2, framePacket, true, true);
  35. });
  36. /**
  37. * Output progress.
  38. */
  39. suite.on('cycle', function (bench, details) {
  40. console.log('\n ' + suite.name.grey, details.name.white.bold);
  41. console.log(' ' + [
  42. details.hz.toFixed(2).cyan + ' ops/sec'.grey
  43. , details.count.toString().white + ' times executed'.grey
  44. , 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
  45. ,
  46. ].join(', '.grey));
  47. });
  48. /**
  49. * Run/export benchmarks.
  50. */
  51. if (!module.parent) {
  52. suite.run();
  53. } else {
  54. module.exports = suite;
  55. }