Skip to content

Commit

Permalink
test: remove BenchmarkNewRewriterBuilder, see #2
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolSpring8 committed Oct 29, 2020
1 parent efe0f5f commit 04c4275
Showing 1 changed file with 0 additions and 96 deletions.
96 changes: 0 additions & 96 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,99 +241,3 @@ func BenchmarkNewWriter(b *testing.B) {
}
}
}

// BenchmarkNewRewriterBuilder tests the cost of not caching the RewriterBuilder.
// In current implementation, every call to NewWriter involves creating a RewriterBuilder.
// Ideally, if multiple documents are to be processed at the same time, a RewriterBuilder
// is created in advance and kept in memory, and Rewriter-s could be built from it.
// This benchmark aims to find out the extent of its impact.
func BenchmarkNewRewriterBuilder(b *testing.B) {
b.Run("Builder", func(b *testing.B) {
for i := 0; i < b.N; i++ {
rb := lolhtml.NewRewriterBuilder()
rb.Free()
}
})
b.Run("BuilderWithEmptyDocumentHandler", func(b *testing.B) {
for i := 0; i < b.N; i++ {
rb := lolhtml.NewRewriterBuilder()
rb.AddDocumentContentHandlers(nil, nil, nil, nil)
rb.Free()
}
})
b.Run("BuilderWithEmptyElementHandler", func(b *testing.B) {
for i := 0; i < b.N; i++ {
rb := lolhtml.NewRewriterBuilder()
s, _ := lolhtml.NewSelector("*")
rb.AddElementContentHandlers(s, nil, nil, nil)
rb.Free()
s.Free()
}
})
b.Run("BuilderWithElementHandler", func(b *testing.B) {
for i := 0; i < b.N; i++ {
rb := lolhtml.NewRewriterBuilder()
s, _ := lolhtml.NewSelector("*")
rb.AddElementContentHandlers(
s,
func(e *lolhtml.Element) lolhtml.RewriterDirective { return lolhtml.Continue },
nil,
nil,
)
rb.Free()
s.Free()
}
})
b.Run("BuilderWithElementHandlerAndBuild", func(b *testing.B) {
for i := 0; i < b.N; i++ {
rb := lolhtml.NewRewriterBuilder()
s, _ := lolhtml.NewSelector("*")
rb.AddElementContentHandlers(
s,
func(e *lolhtml.Element) lolhtml.RewriterDirective { return lolhtml.Continue },
nil,
nil,
)
r, _ := rb.Build(func([]byte) {}, lolhtml.NewDefaultConfig())
r.Free()
rb.Free()
s.Free()
}
})
b.Run("BuildMultipleRewriterFromOneBuilder", func(b *testing.B) {
rb := lolhtml.NewRewriterBuilder()
s, _ := lolhtml.NewSelector("*")
rb.AddElementContentHandlers(
s,
func(e *lolhtml.Element) lolhtml.RewriterDirective { return lolhtml.Continue },
nil,
nil,
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = rb.Build(func([]byte) {}, lolhtml.NewDefaultConfig())
//r.Free() // TODO: fix
}
b.StopTimer()
rb.Free()
s.Free()
})
b.Run("Writer", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := lolhtml.NewWriter(
nil,
&lolhtml.Handlers{
ElementContentHandler: []lolhtml.ElementContentHandler{
{
Selector: "*",
ElementHandler: func(e *lolhtml.Element) lolhtml.RewriterDirective {
return lolhtml.Continue
},
},
},
},
)
r.Free()
}
})
}

0 comments on commit 04c4275

Please sign in to comment.