Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

bench.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* eslint no-console: "off" */
  2. var asynckit = require('./')
  3. , async = require('async')
  4. , assert = require('assert')
  5. , expected = 0
  6. ;
  7. var Benchmark = require('benchmark');
  8. var suite = new Benchmark.Suite;
  9. var source = [];
  10. for (var z = 1; z < 100; z++)
  11. {
  12. source.push(z);
  13. expected += z;
  14. }
  15. suite
  16. // add tests
  17. .add('async.map', function(deferred)
  18. {
  19. var total = 0;
  20. async.map(source,
  21. function(i, cb)
  22. {
  23. setImmediate(function()
  24. {
  25. total += i;
  26. cb(null, total);
  27. });
  28. },
  29. function(err, result)
  30. {
  31. assert.ifError(err);
  32. assert.equal(result[result.length - 1], expected);
  33. deferred.resolve();
  34. });
  35. }, {'defer': true})
  36. .add('asynckit.parallel', function(deferred)
  37. {
  38. var total = 0;
  39. asynckit.parallel(source,
  40. function(i, cb)
  41. {
  42. setImmediate(function()
  43. {
  44. total += i;
  45. cb(null, total);
  46. });
  47. },
  48. function(err, result)
  49. {
  50. assert.ifError(err);
  51. assert.equal(result[result.length - 1], expected);
  52. deferred.resolve();
  53. });
  54. }, {'defer': true})
  55. // add listeners
  56. .on('cycle', function(ev)
  57. {
  58. console.log(String(ev.target));
  59. })
  60. .on('complete', function()
  61. {
  62. console.log('Fastest is ' + this.filter('fastest').map('name'));
  63. })
  64. // run async
  65. .run({ 'async': true });