just-await.benchmark.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /**
  2. * Module dependencies
  3. */
  4. var runBenchmarks = require('../util/run-benchmarks.helper');
  5. var Machine = require('../../');
  6. /* eslint-disable no-unused-vars, camelcase */
  7. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8. // ^^because the snake_case makes test output more readable when working with
  9. // the benchmark.js lib, and the unused vars are there on purpose (to help
  10. // make sure that nothing gets optimized away by V8).
  11. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  12. // ╔═╗╦═╗ ╦╔╦╗╦ ╦╦═╗╔═╗╔═╗
  13. // ╠╣ ║╔╩╦╝ ║ ║ ║╠╦╝║╣ ╚═╗
  14. // ╚ ╩╩ ╚═ ╩ ╚═╝╩╚═╚═╝╚═╝
  15. var doSomethingVerySimple = Machine.build(require('./private/do-something-very-simple.fixture'));
  16. var doSomethingNormal = Machine.build(require('./private/do-something-normal.fixture'));
  17. var doSomethingNormalWithComplexExemplars = Machine.build(require('./private/do-something-normal-with-complex-exemplars.fixture'));
  18. var doSomethingInsaneWithManyBasicExemplars = Machine.build(require('./private/do-something-insane-with-many-basic-exemplars.fixture'));
  19. var doSomethingInsaneButCacheableWithManyBasicExemplars = Machine.build(require('./private/do-something-insane-but-cacheable-with-many-basic-exemplars.fixture'));
  20. var doSomethingInsaneWithManyComplexExemplars = Machine.build(require('./private/do-something-insane-with-many-complex-exemplars.fixture'));
  21. var doSomethingInsaneWithManyRefExemplars = Machine.build(require('./private/do-something-insane-with-many-ref-exemplars.fixture'));
  22. var SAMPLE_USERS = require('./private/sample-users.fixture');
  23. var SAMPLE_SPECIES = require('./private/sample-species.fixture');
  24. var SAMPLE_MANY_BASIC_ARGINS = require('./private/sample-many-basic-argins.fixture');
  25. var SAMPLE_MANY_COMPLEX_ARGINS = require('./private/sample-many-complex-argins.fixture');
  26. // ╔╗ ╔═╗╔╗╔╔═╗╦ ╦╔╦╗╔═╗╦═╗╦╔═╔═╗
  27. // ╠╩╗║╣ ║║║║ ╠═╣║║║╠═╣╠╦╝╠╩╗╚═╗
  28. // ╚═╝╚═╝╝╚╝╚═╝╩ ╩╩ ╩╩ ╩╩╚═╩ ╩╚═╝
  29. describe('benchmark :: just `await` (assuming machines have already been built)', function(){
  30. // Set "timeout" and "slow" thresholds incredibly high
  31. // to avoid running into issues.
  32. this.slow(240000);
  33. this.timeout(240000);
  34. // Skip these tests if node version is too old.
  35. if ((+(process.version.match(/^v([0-9]+)\./)[1])) < 8) {
  36. return;
  37. }//•
  38. it('should be performant enough', function (done){
  39. runBenchmarks('just `await`', [
  40. async function sanity_check(next){
  41. // Do nothing.
  42. return next();
  43. },
  44. async function await_very_simple_machine(next){
  45. await doSomethingVerySimple({});
  46. return next();
  47. },
  48. async function await_machine_with_inputs_and_exits_but_nothing_crazy(next){
  49. await doSomethingNormal({
  50. flavor: 'Sadness',
  51. qty: 1000,
  52. foo: 'wha',
  53. bar: 'huh?'
  54. });
  55. return next();
  56. },
  57. async function await_machine_with_inputs_and_exits_that_have_big_ole_exemplars(next){
  58. await doSomethingNormalWithComplexExemplars({
  59. // Note:
  60. // > We just abritarily use samples from the exemplars as argmts so this
  61. // > benchmark is easier to read.
  62. users: SAMPLE_USERS,
  63. availableSpecies: SAMPLE_SPECIES,
  64. foo: SAMPLE_USERS,
  65. bar: SAMPLE_USERS
  66. });
  67. return next();
  68. },
  69. async function await_machine_with_crazy_numbers_of_inputs_and_exits(next){
  70. await doSomethingInsaneWithManyBasicExemplars(SAMPLE_MANY_BASIC_ARGINS);
  71. return next();
  72. },
  73. async function await_machine_with_crazy_numbers_of_inputs_and_exits_and_is_cacheable(next){
  74. await doSomethingInsaneButCacheableWithManyBasicExemplars(SAMPLE_MANY_BASIC_ARGINS);
  75. return next();
  76. },
  77. async function await_machine_with_crazy_numbers_of_inputs_and_exits_with_huge_exemplars(next){
  78. await doSomethingInsaneWithManyComplexExemplars(SAMPLE_MANY_COMPLEX_ARGINS);
  79. return next();
  80. },
  81. async function await_machine_with_crazy_numbers_of_inputs_and_exits_with_ref_exemplars(next){
  82. await doSomethingInsaneWithManyRefExemplars(SAMPLE_MANY_COMPLEX_ARGINS);
  83. return next();
  84. },
  85. // ================================================================================
  86. // async function sanity_check(next){
  87. // (async function(){
  88. // // Do nothing.
  89. // })().then(function(){
  90. // return next();
  91. // }).catch(function(err){
  92. // return next(err);
  93. // });
  94. // },
  95. // function await_very_simple_machine(next){
  96. // (async function(){
  97. // await doSomethingVerySimple({});
  98. // })().then(function(){
  99. // return next();
  100. // }).catch(function(err){
  101. // return next(err);
  102. // });
  103. // },
  104. // function await_machine_with_inputs_and_exits_but_nothing_crazy(next){
  105. // (async function(){
  106. // await doSomethingNormal({
  107. // flavor: 'Sadness',
  108. // qty: 1000,
  109. // foo: 'wha',
  110. // bar: 'huh?'
  111. // });
  112. // })().then(function(){
  113. // return next();
  114. // }).catch(function(err){
  115. // return next(err);
  116. // });
  117. // },
  118. // function await_machine_with_inputs_and_exits_that_have_big_ole_exemplars(next){
  119. // (async function(){
  120. // await doSomethingNormalWithComplexExemplars({
  121. // // Note:
  122. // // > We just abritarily use samples from the exemplars as argmts so this
  123. // // > benchmark is easier to read.
  124. // users: SAMPLE_USERS,
  125. // availableSpecies: SAMPLE_SPECIES,
  126. // foo: SAMPLE_USERS,
  127. // bar: SAMPLE_USERS
  128. // });
  129. // })().then(function(){
  130. // return next();
  131. // }).catch(function(err){
  132. // return next(err);
  133. // });
  134. // },
  135. // function await_machine_with_crazy_numbers_of_inputs_and_exits(next){
  136. // (async function(){
  137. // await doSomethingInsaneWithManyBasicExemplars(SAMPLE_MANY_BASIC_ARGINS);
  138. // })().then(function(){
  139. // return next();
  140. // }).catch(function(err){
  141. // return next(err);
  142. // });
  143. // },
  144. // function await_machine_with_crazy_numbers_of_inputs_and_exits_and_is_cacheable(next){
  145. // (async function(){
  146. // await doSomethingInsaneButCacheableWithManyBasicExemplars(SAMPLE_MANY_BASIC_ARGINS);
  147. // })().then(function(){
  148. // return next();
  149. // }).catch(function(err){
  150. // return next(err);
  151. // });
  152. // },
  153. // function await_machine_with_crazy_numbers_of_inputs_and_exits_with_huge_exemplars(next){
  154. // (async function(){
  155. // await doSomethingInsaneWithManyComplexExemplars(SAMPLE_MANY_COMPLEX_ARGINS);
  156. // })().then(function(){
  157. // return next();
  158. // }).catch(function(err){
  159. // return next(err);
  160. // });
  161. // },
  162. // function await_machine_with_crazy_numbers_of_inputs_and_exits_with_ref_exemplars(next){
  163. // (async function(){
  164. // await doSomethingInsaneWithManyRefExemplars(SAMPLE_MANY_COMPLEX_ARGINS);
  165. // })().then(function(){
  166. // return next();
  167. // }).catch(function(err){
  168. // return next(err);
  169. // });
  170. // },
  171. ], done);
  172. });//</should be performant enough>
  173. });