runner.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Benchmark runner dependencies
  3. */
  4. var colors = require('colors')
  5. , path = require('path');
  6. /**
  7. * Find all the benchmarks
  8. */
  9. var benchmarks_files = process.env.BENCHMARKS.split(' ')
  10. , all = [].concat(benchmarks_files)
  11. , first = all.shift()
  12. , benchmarks = {};
  13. // find the benchmarks and load them all in our obj
  14. benchmarks_files.forEach(function (file) {
  15. benchmarks[file] = require(path.join(__dirname, '..', file));
  16. });
  17. // setup the complete listeners
  18. benchmarks_files.forEach(function (file) {
  19. var benchmark = benchmarks[file]
  20. , next_file = all.shift()
  21. , next = benchmarks[next_file];
  22. /**
  23. * Generate a oncomplete function for the tests, either we are done or we
  24. * have more benchmarks to process.
  25. */
  26. function complete () {
  27. if (!next) {
  28. console.log(
  29. '\n\nBenchmark completed in'.grey
  30. , (Date.now() - start).toString().green + ' ms'.grey
  31. );
  32. } else {
  33. console.log('\nStarting benchmark '.grey + next_file.yellow);
  34. next.run();
  35. }
  36. }
  37. // attach the listener
  38. benchmark.on('complete', complete);
  39. });
  40. /**
  41. * Start the benchmark
  42. */
  43. var start = Date.now();
  44. console.log('Starting benchmark '.grey + first.yellow);
  45. benchmarks[first].run();