aboutsummaryrefslogtreecommitdiff
path: root/js/bench.js
blob: d1e33847e74abab086cb8e8184dd34baf218fd22 (plain)
  1. var Benchmark = require('benchmark').Benchmark;
  2. var suite = new Benchmark.Suite();
  3. var fs = require('fs');
  4. var sm = require('./lib/index.js');
  5. // npm install showdown
  6. var Showdown = require('showdown').converter;
  7. // npm install marked
  8. var marked = require('marked');
  9. // npm install markdown-it
  10. var markdownit = require('markdown-it')('commonmark');
  11. var benchfile = process.argv[2];
  12. var contents = fs.readFileSync(benchfile, 'utf8');
  13. suite.add('commonmark.js markdown->html', function() {
  14. "use strict";
  15. var doc = new sm.DocParser().parse(contents);
  16. var renderer = new sm.HtmlRenderer();
  17. renderer.render(doc);
  18. })
  19. .add('showdown.js markdown->html', function() {
  20. "use strict";
  21. var converter = new Showdown();
  22. converter.makeHtml(contents);
  23. })
  24. .add('marked.js markdown->html', function() {
  25. "use strict";
  26. marked(contents);
  27. })
  28. .add('markdown-it markdown->html', function() {
  29. "use strict";
  30. markdownit.render(contents);
  31. })
  32. .on('cycle', function(event) {
  33. "use strict";
  34. console.log(String(event.target));
  35. })
  36. .run();