diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-08-17 13:41:48 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-09-14 10:57:39 +0200 |
commit | dd45e6d7e5406991d8df3a2f9ba4c7e5ae039c34 (patch) | |
tree | 0eaf4d028091ab7ee1c0997eb722442c0328c817 /helpers/content_test.go | |
parent | 4abaec5c045e92ae5f8b3a2dc66606b080ef6ea5 (diff) |
Lazy calculate WordCount, ReadingTime and FuzzyWordCount
This avoids having to execute these expensive operations for sites not using these values.
This commit sums up a set of wordcounting and autosummary related performance improvements.
The effect of these kind of depends on what features your site use, but a benchmark from 4 Hugo sites in the wild shows promise:
```
benchmark old ns/op new ns/op delta
BenchmarkHugo-4 21293005843 20032857342 -5.92%
benchmark old allocs new allocs delta
BenchmarkHugo-4 65290922 65186032 -0.16%
benchmark old bytes new bytes delta
BenchmarkHugo-4 9771213416 9681866464 -0.91%
```
Closes #2378
Diffstat (limited to 'helpers/content_test.go')
-rw-r--r-- | helpers/content_test.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/helpers/content_test.go b/helpers/content_test.go index 82af70f8f..22c81005f 100644 --- a/helpers/content_test.go +++ b/helpers/content_test.go @@ -34,11 +34,22 @@ func TestStripHTML(t *testing.T) { } data := []test{ {"<h1>strip h1 tag <h1>", "strip h1 tag "}, - {"<p> strip p tag </p>", " strip p tag \n"}, + {"<p> strip p tag </p>", " strip p tag "}, {"</br> strip br<br>", " strip br\n"}, {"</br> strip br2<br />", " strip br2\n"}, {"This <strong>is</strong> a\nnewline", "This is a newline"}, {"No Tags", "No Tags"}, + {`<p>Summary Next Line. +<figure > + + <img src="/not/real" /> + + +</figure> +. +More text here.</p> + +<p>Some more text</p>`, "Summary Next Line. . More text here.\nSome more text\n"}, } for i, d := range data { output := StripHTML(d.input) |