Skip to content
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

strings.EqualsFold() is faster #47

Open
azumakuniyuki opened this issue Feb 6, 2025 · 0 comments
Open

strings.EqualsFold() is faster #47

azumakuniyuki opened this issue Feb 6, 2025 · 0 comments
Labels
speed-up Performance Tuning

Comments

@azumakuniyuki
Copy link
Member

azumakuniyuki commented Feb 6, 2025

package main
import (
    "strings"
    "testing"
)
var Text = "rfc822"

func BenchmarkToLower(b *testing.B) {
    cv := "RFC822"
	ci := 0
    for i := 0; i < b.N; i++ { if strings.ToLower(cv) == Text { ci++ } }
}

func BenchmarkEqualFold(b *testing.B) {
    cv := "RFC822"
	ci := 0
    for i := 0; i < b.N; i++ { if strings.EqualFold(cv, Text) { ci++ } }
}
% go test -bench=.
goos: darwin
goarch: amd64
pkg: libsisimai.org/sisimai/benchmark/equalfold
cpu: Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
BenchmarkToLower-4     	14093912	        86.34 ns/op
BenchmarkEqualFold-4   	58651954	        19.54 ns/op
PASS
ok  	libsisimai.org/sisimai/benchmark/equalfold	4.263s
go test -bench=.  3.78s user 0.95s system 83% cpu 5.653 total
@azumakuniyuki azumakuniyuki added the speed-up Performance Tuning label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speed-up Performance Tuning
Projects
None yet
Development

No branches or pull requests

1 participant