forked from vanng822/go-premailer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.go
70 lines (64 loc) · 1.37 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
package premailer
import (
"bytes"
"testing"
)
var (
testBenmarkBuf *bytes.Buffer
testBenmarkHtmlBytes []byte
testBenmarkHtml string
)
func init() {
testBenmarkBuf = new(bytes.Buffer)
testString := `<html>
<head>
<title>Title</title>
<style type="text/css">
h1 {
width: 50px;
color:red;
}
h2 {
vertical-align: top;
}
h3 {
text-align: right;
}
strong {
text-decoration:none
}
div {
background-color: green
}
</style>
</head>
<body>
<h1>Hi!</h1>
<h2>There</h2>
<h3>Hello</h3>
<p><strong>Yes!</strong></p>
<div>Green color</div>
</body>
</html>`
testBenmarkBuf.WriteString(testString)
testBenmarkHtml = testString
testBenmarkHtmlBytes = []byte(testString)
}
func BenchmarkPremailerBasicHTMLBytes(b *testing.B) {
for n := 0; n < b.N; n++ {
p, _ := NewPremailerFromBytes(testBenmarkHtmlBytes, nil)
p.Transform()
}
}
func BenchmarkPremailerBasicHTML(b *testing.B) {
for n := 0; n < b.N; n++ {
p, _ := NewPremailerFromString(testBenmarkHtml, nil)
p.Transform()
}
}
func BenchmarkPremailerBasicHTMLBytes2String(b *testing.B) {
for n := 0; n < b.N; n++ {
p, _ := NewPremailerFromString(testBenmarkBuf.String(), nil)
p.Transform()
}
}