Skip to content

Commit

Permalink
Adding basic html benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
unrolled committed May 12, 2021
1 parent b7951a4 commit cb349b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 4 additions & 6 deletions render_html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,11 @@ func TestHTMLExtensions(t *testing.T) {
func TestHTMLFuncs(t *testing.T) {
render := New(Options{
Directory: "fixtures/custom_funcs",
Funcs: []template.FuncMap{
template.FuncMap{
"myCustomFunc": func() string {
return "My custom function"
},
Funcs: []template.FuncMap{{
"myCustomFunc": func() string {
return "My custom function"
},
},
}},
})

var err error
Expand Down
18 changes: 18 additions & 0 deletions render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ func BenchmarkStreamingJSON(b *testing.B) {
}
}

func BenchmarkHTML(b *testing.B) {
render := New(Options{
Directory: "fixtures/basic",
})

h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_ = render.HTML(w, http.StatusOK, "hello", "gophers")
})
req, _ := http.NewRequest("GET", "/foo", nil)

b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
h.ServeHTTP(httptest.NewRecorder(), req)
}
})
}

/* Test Helper */
func expect(t *testing.T, a interface{}, b interface{}) {
if a != b {
Expand Down

0 comments on commit cb349b4

Please sign in to comment.