Remove `String#casecmp` part
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- documentation
Research direction
No file, test, or entry point is named. First locate the documentation section for String#casecmp, review the Unicode examples and benchmark context, and remove the requested String#casecmp portion while preserving accurate guidance about String#downcase + ==.
Written by the indexing model from the issue text.
Description
The String#casecmp method does not work with Unicode (even in Ruby 2.4.1), this is written in the documentation.
Example:
'Привет'.casecmp('привет') # => -1
There is a method String#casecmp?, which works with Unicode.
Example:
'Привет'.casecmp?('привет') # => true
But String.casecmp? is slower:
Warming up --------------------------------------
String#downcase + == 233.440k i/100ms
String#casecmp 274.247k i/100ms
String#casecmp? 219.906k i/100ms
Calculating -------------------------------------
String#downcase + == 5.746M (± 1.7%) i/s - 28.947M in 5.039252s
String#casecmp 6.942M (± 1.8%) i/s - 34.829M in 5.019073s
String#casecmp? 4.517M (± 2.6%) i/s - 22.650M in 5.017864s
Comparison:
String#casecmp: 6941676.9 i/s
String#downcase + ==: 5745893.8 i/s - 1.21x slower
String#casecmp?: 4517314.3 i/s - 1.54x slower
Code
require 'benchmark/ips'
SLUG = 'ABCD'
def slow
SLUG.downcase == 'abcd'
end
def fast
SLUG.casecmp('abcd') == 0
end
def another
SLUG.casecmp?('abcd')
end
Benchmark.ips do |x|
x.report('String#downcase + ==') { slow }
x.report('String#casecmp') { fast }
x.report('String#casecmp?') { another }
x.compare!
end
So, String#downcase + == is good compromise.
- Dominant language
- Ruby
- Stars
- 5.7k
- Forks
- 370
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fastruby/fast-ruby
-
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
All issues in fastruby/fast-ruby
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
palladius/rails8-app-on-gcp#145 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
rubocop/rubocop-rspec#2236 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
riscv/riscv-unified-db#2624 · 1 reaction ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100