benchmark_suite.js 944 B

123456789101112131415161718192021222324252627282930313233
  1. var benchmark = require("benchmark");
  2. function newBenchmark(messageName, filename, language) {
  3. var benches = [];
  4. return {
  5. suite: new benchmark.Suite(messageName + filename + language )
  6. .on("add", function(event) {
  7. benches.push(event.target);
  8. })
  9. .on("start", function() {
  10. process.stdout.write(
  11. "benchmarking message " + messageName
  12. + " of dataset file " + filename
  13. + "'s performance ..." + "\n\n");
  14. })
  15. .on("cycle", function(event) {
  16. process.stdout.write(String(event.target) + "\n");
  17. })
  18. .on("complete", function() {
  19. var getHz = function(bench) {
  20. return 1 / (bench.stats.mean + bench.stats.moe);
  21. }
  22. benches.forEach(function(val, index) {
  23. benches[index] = getHz(val);
  24. });
  25. }),
  26. benches: benches
  27. }
  28. }
  29. module.exports = {
  30. newBenchmark: newBenchmark
  31. }