-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Optimize String#compare in case of ASCII only #7352
Conversation
What about longer and much longer strings? |
@ysbaddaden then it's even slower: string = "aA" * 500
Benchmark.ips do |bm|
bm.report "String#new_compare for ASCII" do
string.new_compare(string, true) == 0
end
bm.report "String#compare for ASCII" do
string.compare(string, true) == 0
end
end
string1 = "aA" * 5000
string2 = "aa" * 5000
Benchmark.ips do |bm|
bm.report "String#new_compare for ASCII" do
string1.new_compare(string2, true) == 0
end
bm.report "String#compare for ASCII" do
string1.compare(string2, true) == 0
end
end
|
Great! |
I changed But also, I've scrolled for quite some time through this: https://github.com/search?l=C&o=asc&q=strcasecmp&s=indexed&type=Code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't drop #compare
because you don't like it: you're throwing away the possibility to compare strings case insensitively.
A use case: sort strings case insensitive. |
ok I think I've found a relatively efficient way to do it now. |
Having |
A bug in the Crystal compiler occurred in the test_darwin CircleCI. Doesn't seem to be related. |
CI failed on Darwin with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation might be fast, but it doesn't seem to be anywhere complete.
Please add an example where a case-insensitive comparing character is not the first one but somewhere further inside the string.
@r00ster91 would you mind doing a rebase on master so the CI can be happy? |
Thanks @r00ster91 🙇 |
This optimizes
String#compare
whenother
andself
is ASCII: