Skip to content

Commit 73eb1ff

Browse files
author
Artyom Pervukhin
committed
Add ProcessHTML method benchmark
1 parent 8b5150f commit 73eb1ff

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

opengraph/opengraph_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"github.com/dyatlov/go-opengraph/opengraph"
99
)
1010

11-
func TestOpenGraphProcessHTML(t *testing.T) {
12-
html := `
11+
const html = `
1312
<!DOCTYPE html>
1413
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
1514
<head profile="http://gmpg.org/xfn/11">
@@ -31,6 +30,19 @@ func TestOpenGraphProcessHTML(t *testing.T) {
3130
<meta name="twitter:card" content="summary" />
3231
<meta name="twitter:creator" content="@WordPress" />
3332
`
33+
34+
func BenchmarkOpenGraph_ProcessHTML(b *testing.B) {
35+
og := opengraph.NewOpenGraph()
36+
b.ReportAllocs()
37+
b.SetBytes(int64(len(html)))
38+
for i := 0; i < b.N; i++ {
39+
if err := og.ProcessHTML(strings.NewReader(html)); err != nil {
40+
b.Fatal(err)
41+
}
42+
}
43+
}
44+
45+
func TestOpenGraphProcessHTML(t *testing.T) {
3446
og := opengraph.NewOpenGraph()
3547
err := og.ProcessHTML(strings.NewReader(html))
3648

0 commit comments

Comments
 (0)