diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-04-11 11:27:07 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-04-11 11:33:58 +0200 |
commit | 13dac7f3cd68789479399a9b0c1756d718e70805 (patch) | |
tree | b54c0777bea70685482b3bbb09076326ce09ba8d /compare | |
parent | 30c2e54c25f6c3a942080f30be49712adda27586 (diff) | |
download | hugo-13dac7f3cd68789479399a9b0c1756d718e70805.tar.gz hugo-13dac7f3cd68789479399a9b0c1756d718e70805.zip |
compare: Add a string sort benchmark
Diffstat (limited to 'compare')
-rw-r--r-- | compare/compare_strings_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compare/compare_strings_test.go b/compare/compare_strings_test.go index 9c4aa5868..a73091fc6 100644 --- a/compare/compare_strings_test.go +++ b/compare/compare_strings_test.go @@ -62,3 +62,22 @@ func TestLexicographicSort(t *testing.T) { c.Assert(s, qt.DeepEquals, []string{"A", "b", "Ba", "ba", "ba", "Bz"}) } + +func BenchmarkStringSort(b *testing.B) { + prototype := []string{"b", "Bz", "zz", "ba", "αβδ αβδ αβδ", "A", "Ba", "ba", "nnnnasdfnnn", "AAgæåz", "αβδC"} + b.Run("LessStrings", func(b *testing.B) { + ss := make([][]string, b.N) + for i := 0; i < b.N; i++ { + ss[i] = make([]string, len(prototype)) + copy(ss[i], prototype) + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + sss := ss[i] + sort.Slice(sss, func(i, j int) bool { + return LessStrings(sss[i], sss[j]) + }) + } + }) + +} |