Advertisement
lignite0

JS Benchmark runner

Oct 21st, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Benchmark from "benchmark";
  2.  
  3. (async function () {
  4.     const suite = new Benchmark.Suite();
  5.     const module = await import(process.argv[2]);
  6.     for (let testName of Object.keys(module)) {
  7.         const provider = module[testName];
  8.         const testFunction = provider();
  9.         const result = testFunction();
  10.         console.log(`Test ${testName} return (${result})`);
  11.         suite.add(testName, testFunction);
  12.     }
  13.  
  14.     suite.on('cycle', function (event) {
  15.         console.log(String(event.target));
  16.     });
  17.     suite.on('complete', function () {
  18.         console.log('Fastest is ' + this.filter('fastest').map('name'));
  19.     });
  20.     suite.run();
  21. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement