Skip to content

Conversation

Nigel2392
Copy link
Contributor

@Nigel2392 Nigel2392 commented Jul 28, 2025

The benchmark tests for strings.(Namespace).Truncate was rather simple, only testing for very short strings.

I have added 4 benchmarks, one for long and medium plain text and one for long and medium HTML text.

Results (from my local machine) can be seen in the following table:

goos: windows
goarch: amd64
pkg: github.com/gohugoio/hugo/tpl/strings
cpu: 12th Gen Intel(R) Core(TM) i5-1235U
BenchmarkTruncate/Plain_text_(medium)-12         	214671	       5737 ns/op	      384 B/op	       1 allocs/op
BenchmarkTruncate/With_HTML_(medium)-12          	192727	       6150 ns/op	    1248 B/op	       3 allocs/op
BenchmarkTruncate/Plain_text_(long)-12           	          40849	     27711 ns/op	    2048 B/op	       1 allocs/op
BenchmarkTruncate/HTML_text_(long)-12            	          40664	     30509 ns/op	    6144 B/op	       3 allocs/op
PASS
ok  	github.com/gohugoio/hugo/tpl/strings	9.075s

@CLAassistant
Copy link

CLAassistant commented Jul 28, 2025

CLA assistant check
All committers have signed the CLA.

@Nigel2392
Copy link
Contributor Author

The benchmark tests are all wrong, even previously. The strings should have been cast to template.HTML.
Will fix tomorrow.

From Github web
@Nigel2392
Copy link
Contributor Author

The new benchmark results:

BenchmarkTruncate/Plain_text-12         	 6716235	       182.9 ns/op	      16 B/op	       1 allocs/op
BenchmarkTruncate/With_link-12          	  983589	      1286 ns/op	     161 B/op	       5 allocs/op
BenchmarkTruncate/Plain_text_(medium)-12         	  204534	      5946 ns/op	     384 B/op	       1 allocs/op
BenchmarkTruncate/With_HTML_(medium)-12          	   45519	     25717 ns/op	    2003 B/op	      24 allocs/op
BenchmarkTruncate/Plain_text_(long)-12           	   41742	     28162 ns/op	    2048 B/op	       1 allocs/op
BenchmarkTruncate/HTML_text_(long)-12            	    8776	    144759 ns/op	    4657 B/op	      48 allocs/op

@Nigel2392 Nigel2392 changed the title Add truncate benchmark tests for longer strings Fix truncate benchmarks, add more benchmark tests for longer strings Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants