mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-23 06:20:49 +00:00
compare: Add a string sort benchmark
This commit is contained in:
parent
30c2e54c25
commit
13dac7f3cd
1 changed files with 19 additions and 0 deletions
|
@ -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])
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue