small.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var Seq = require('seq');
  2. var Hash = require('hashish');
  3. var Bin = require('binary');
  4. var Buf = require('bufferlist/binary');
  5. var BufferList = require('bufferlist');
  6. var EventEmitter = require('events').EventEmitter;
  7. function binary (buf, cb) {
  8. Bin(buf)
  9. .word32le('x')
  10. .word16be('y')
  11. .word16be('z')
  12. .word32le('w')
  13. .tap(cb)
  14. ;
  15. };
  16. function stream (buf, cb) {
  17. var em = new EventEmitter;
  18. Bin(em)
  19. .word32le('x')
  20. .word16be('y')
  21. .word16be('z')
  22. .word32le('w')
  23. .tap(cb)
  24. ;
  25. em.emit('data', buf);
  26. };
  27. function parse (buf, cb) {
  28. cb(Bin.parse(buf)
  29. .word32le('x')
  30. .word16be('y')
  31. .word16be('z')
  32. .word32le('w')
  33. .vars
  34. );
  35. };
  36. function bufferlist (buf, cb) {
  37. var blist = new BufferList;
  38. blist.push(buf);
  39. Buf(blist)
  40. .getWord32le('x')
  41. .getWord16be('y')
  42. .getWord16be('z')
  43. .getWord32le('w')
  44. .tap(cb)
  45. .end()
  46. ;
  47. };
  48. var buffers = [];
  49. for (var i = 0; i < 200; i++) {
  50. buffers.push(new Buffer(12));
  51. }
  52. console.log('small');
  53. Seq(binary, stream, parse, bufferlist)
  54. .seqEach(function (f) {
  55. var t = this;
  56. var t0 = Date.now();
  57. Seq()
  58. .extend(buffers)
  59. .seqEach(function (buf) {
  60. f(buf, this.bind(this, null));
  61. })
  62. .seq(function () {
  63. var tf = Date.now();
  64. console.log(' ' + f.name + ': ' + (tf - t0));
  65. t(null);
  66. })
  67. ;
  68. })
  69. .seq(function () {
  70. this(null);
  71. })
  72. ;