bench-sync.util.js 805 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Module dependencies
  3. */
  4. var _ = require('@sailshq/lodash');
  5. var Benchmark = require('benchmark');
  6. /**
  7. * benchSync()
  8. *
  9. * (see https://benchmarkjs.com/docs#Benchmark)
  10. * ---------------------------
  11. * @param {String} name
  12. * @param {Array} testFns [array of functions]
  13. */
  14. module.exports = function benchSync (name, testFns) {
  15. var suite = new Benchmark.Suite({ name: name });
  16. _.each(testFns, function (testFn, i) {
  17. suite = suite.add((testFn.name||name)+'#'+i, testFn);
  18. });//</each testFn>
  19. suite.on('cycle', function(event) {
  20. console.log(' •',String(event.target));
  21. })
  22. .on('complete', function() {
  23. // console.log('Fastest is ' + this.filter('fastest').map('name'));
  24. // console.log('Slowest is ' + this.filter('slowest').map('name'));
  25. })
  26. .run();
  27. };