-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compare with EqualFold instead of ToLower #48
Comments
Sure, |
For reference, here is a very simple micro-benchmark: package main
import (
"strings"
"testing"
)
func BenchmarkToLower(b *testing.B) {
for i := 0; i < b.N; i++ {
if strings.ToLower("ABCDEFGHIJ") != "abcdefghij" {
b.Fatal("not equal")
}
}
}
func BenchmarkEqualFold(b *testing.B) {
for i := 0; i < b.N; i++ {
if !strings.EqualFold("ABCDEFGHIJ", "abcdefghij") {
b.Fatal("not equal")
}
}
} The result
I tried to integrate the benchmark to |
emersion
pushed a commit
that referenced
this issue
Mar 31, 2021
It doesn't allocate a new string each time. Fixes #48
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did a profiling of my application, and noticed that
msgauth/dkim
is comparing strings withToLower
.go-msgauth/dkim/header.go
Lines 152 to 158 in e98a2ee
go-msgauth/dkim/verify.go
Line 244 in e98a2ee
Each time this function is called, it allocates a new string, which creates more work for the garbage collector.
I think there is an "allocation free" alternative:
EqualFold
.WDYT ?
I can submit a benchmark if needed.
The text was updated successfully, but these errors were encountered: