summaryrefslogtreecommitdiff
path: root/js/bench.js
blob: d1e33847e74abab086cb8e8184dd34baf218fd22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var Benchmark = require('benchmark').Benchmark;
var suite = new Benchmark.Suite();
var fs = require('fs');
var sm = require('./lib/index.js');
// npm install showdown
var Showdown = require('showdown').converter;
// npm install marked
var marked = require('marked');
// npm install markdown-it
var markdownit = require('markdown-it')('commonmark');

var benchfile = process.argv[2];

var contents = fs.readFileSync(benchfile, 'utf8');

suite.add('commonmark.js markdown->html', function() {
  "use strict";
  var doc = new sm.DocParser().parse(contents);
  var renderer = new sm.HtmlRenderer();
  renderer.render(doc);
})

.add('showdown.js markdown->html', function() {
  "use strict";
  var converter = new Showdown();
  converter.makeHtml(contents);
})

.add('marked.js markdown->html', function() {
  "use strict";
  marked(contents);
})

.add('markdown-it markdown->html', function() {
  "use strict";
  markdownit.render(contents);
})

.on('cycle', function(event) {
  "use strict";
  console.log(String(event.target));
})
.run();