diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-20 16:50:03 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-20 17:24:17 +0200 |
commit | ef34dd8f0e94e52ba6f1d5d607e4ac3ae98a7abb (patch) | |
tree | 6cccbecf2bf0a899bb61c87eb52e981198355ad9 /publisher/htmlElementsCollector_test.go | |
parent | bc80022e033a5462d1a9ce541f40a050994011cc (diff) |
publisher: Some performance tweaks for the HTML elements collector
Diffstat (limited to 'publisher/htmlElementsCollector_test.go')
-rw-r--r-- | publisher/htmlElementsCollector_test.go | 70 |
1 files changed, 1 insertions, 69 deletions
diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go index 1ada27c18..0c8b2b65b 100644 --- a/publisher/htmlElementsCollector_test.go +++ b/publisher/htmlElementsCollector_test.go @@ -14,7 +14,6 @@ package publisher import ( - "bytes" "fmt" "strings" "testing" @@ -129,33 +128,8 @@ func TestClassCollector(t *testing.T) { } } -func BenchmarkClassCollectorWriter(b *testing.B) { +func BenchmarkElementsCollectorWriter(b *testing.B) { const benchHTML = ` -<html> -<body id="i1" class="a b c d"> -<a class="c d e"></a> -<br> -<a class="c d e"></a> -<a class="c d e"></a> -<br> -<a id="i2" class="c d e f"></a> -<a id="i3" class="c d e"></a> -<a class="c d e"></a> -<br> -<a class="c d e"></a> -<a class="c d e"></a> -<a class="c d e"></a> -<a class="c d e"></a> -</body> -</html> -` - for i := 0; i < b.N; i++ { - w := newHTMLElementsCollectorWriter(newHTMLElementsCollector()) - fmt.Fprint(w, benchHTML) - } -} - -const benchHTML = ` <!DOCTYPE html> <html> <head> @@ -207,51 +181,9 @@ const benchHTML = ` </body> </html> ` - -func BenchmarkElementsCollectorWriter(b *testing.B) { - b.ReportAllocs() for i := 0; i < b.N; i++ { w := newHTMLElementsCollectorWriter(newHTMLElementsCollector()) fmt.Fprint(w, benchHTML) - } -} - -func BenchmarkElementsCollectorWriterMinified(b *testing.B) { - b.ReportAllocs() - v := viper.New() - m, _ := minifiers.New(media.DefaultTypes, output.DefaultFormats, v) - var buf bytes.Buffer - m.Minify(media.HTMLType, &buf, strings.NewReader(benchHTML)) - b.ResetTimer() - - for i := 0; i < b.N; i++ { - w := newHTMLElementsCollectorWriter(newHTMLElementsCollector()) - fmt.Fprint(w, buf.String()) - } -} - -func BenchmarkElementsCollectorWriterWithMinifyStream(b *testing.B) { - b.ReportAllocs() - v := viper.New() - m, _ := minifiers.New(media.DefaultTypes, output.DefaultFormats, v) - b.ResetTimer() - - for i := 0; i < b.N; i++ { - w := newHTMLElementsCollectorWriter(newHTMLElementsCollector()) - m.Minify(media.HTMLType, w, strings.NewReader(benchHTML)) - } -} - -func BenchmarkElementsCollectorWriterWithMinifyString(b *testing.B) { - b.ReportAllocs() - v := viper.New() - m, _ := minifiers.New(media.DefaultTypes, output.DefaultFormats, v) - b.ResetTimer() - for i := 0; i < b.N; i++ { - var buf bytes.Buffer - m.Minify(media.HTMLType, &buf, strings.NewReader(benchHTML)) - w := newHTMLElementsCollectorWriter(newHTMLElementsCollector()) - fmt.Fprint(w, buf.String()) } } |