function_args.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const path = require('path');
  2. const Benchmark = require('benchmark');
  3. const addonName = path.basename(__filename, '.js');
  4. [ addonName, addonName + '_noexcept' ]
  5. .forEach((addonName) => {
  6. const rootAddon = require(`./build/Release/${addonName}`);
  7. const implems = Object.keys(rootAddon);
  8. const anObject = {};
  9. console.log(`${addonName}: `);
  10. console.log('no arguments:');
  11. implems.reduce((suite, implem) => {
  12. const fn = rootAddon[implem].noArgFunction;
  13. return suite.add(implem, () => fn());
  14. }, new Benchmark.Suite)
  15. .on('cycle', (event) => console.log(String(event.target)))
  16. .run();
  17. console.log('one argument:');
  18. implems.reduce((suite, implem) => {
  19. const fn = rootAddon[implem].oneArgFunction;
  20. return suite.add(implem, () => fn('x'));
  21. }, new Benchmark.Suite)
  22. .on('cycle', (event) => console.log(String(event.target)))
  23. .run();
  24. console.log('two arguments:');
  25. implems.reduce((suite, implem) => {
  26. const fn = rootAddon[implem].twoArgFunction;
  27. return suite.add(implem, () => fn('x', 12));
  28. }, new Benchmark.Suite)
  29. .on('cycle', (event) => console.log(String(event.target)))
  30. .run();
  31. console.log('three arguments:');
  32. implems.reduce((suite, implem) => {
  33. const fn = rootAddon[implem].threeArgFunction;
  34. return suite.add(implem, () => fn('x', 12, true));
  35. }, new Benchmark.Suite)
  36. .on('cycle', (event) => console.log(String(event.target)))
  37. .run();
  38. console.log('four arguments:');
  39. implems.reduce((suite, implem) => {
  40. const fn = rootAddon[implem].fourArgFunction;
  41. return suite.add(implem, () => fn('x', 12, true, anObject));
  42. }, new Benchmark.Suite)
  43. .on('cycle', (event) => console.log(String(event.target)))
  44. .run();
  45. });