forked from b3log/go-markdown-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.go
107 lines (95 loc) · 2.8 KB
/
benchmark_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Lute - A structured markdown engine.
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// PURPOSE.
// See the Mulan PSL v1 for more details.
package main
import (
"bytes"
"io/ioutil"
"testing"
"github.com/b3log/lute"
"gopkg.in/russross/blackfriday.v2"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/renderer/html"
"gitlab.com/golang-commonmark/markdown"
)
func BenchmarkLute(b *testing.B) {
spec := "commonmark-spec"
bytes, err := ioutil.ReadFile(spec + ".md")
if nil != err {
b.Fatalf("read spec text failed: " + err.Error())
}
luteEngine := lute.New()
luteEngine.GFMTaskListItem = true
luteEngine.GFMTable = true
luteEngine.GFMAutoLink = true
luteEngine.GFMStrikethrough = true
luteEngine.SoftBreak2HardBreak = false
luteEngine.CodeSyntaxHighlight = false
luteEngine.AutoSpace = false
luteEngine.FixTermTypo = false
luteEngine.ChinesePunct = false
luteEngine.Emoji = false
html, err := luteEngine.Markdown("spec text", bytes)
if nil != err {
b.Fatalf("unexpected: %s", err)
}
if err := ioutil.WriteFile(spec+".html", html, 0644); nil != err {
b.Fatalf("write spec html failed: %s", err)
}
for i := 0; i < b.N; i++ {
luteEngine.Markdown("spec text", bytes)
}
}
func BenchmarkGolangCommonMark(b *testing.B) {
spec := "../test/commonmark-spec"
bytes, err := ioutil.ReadFile(spec + ".md")
if nil != err {
b.Fatalf("read spec text failed: " + err.Error())
}
md := markdown.New(markdown.XHTMLOutput(true),
markdown.Tables(true),
markdown.Linkify(true),
markdown.Typographer(false))
for i := 0; i < b.N; i++ {
md.RenderToString(bytes)
}
}
func BenchmarkGoldMark(b *testing.B) {
spec := "../test/commonmark-spec"
markdown, err := ioutil.ReadFile(spec + ".md")
if nil != err {
b.Fatalf("read spec text failed: " + err.Error())
}
goldmarkEngine := goldmark.New(
goldmark.WithRendererOptions(html.WithXHTML()),
goldmark.WithExtensions(
extension.Table, extension.Strikethrough, extension.TaskList, extension.Linkify,
),
)
var out bytes.Buffer
for i := 0; i < b.N; i++ {
out.Reset()
if err := goldmarkEngine.Convert(markdown, &out); nil != err {
panic(err)
}
}
}
func BenchmarkBlackFriday(b *testing.B) {
spec := "../test/commonmark-spec"
markdown, err := ioutil.ReadFile(spec + ".md")
if nil != err {
b.Fatalf("read spec text failed: " + err.Error())
}
for i := 0; i < b.N; i++ {
blackfriday.Run(markdown)
}
}