Skip to content

Commit

Permalink
compare: Add a string sort benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 11, 2022
1 parent 30c2e54 commit 13dac7f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions compare/compare_strings_test.go
Expand Up @@ -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])
})
}
})

}

0 comments on commit 13dac7f

Please sign in to comment.