Comparison logic vs `between?` vs `include?`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- performance
Research direction
Start with the benchmark shown in the issue and inspect the repository’s existing comparison entries to find where this result belongs. Confirm the intended change with maintainers, then ensure the comparison is represented consistently and its benchmark results are reproducible.
Written by the indexing model from the issue text.
Description
#!/usr/local/bin/ruby
require 'benchmark/ips'
Benchmark.ips do |x|
value = 42
x.report('>= && <=') { value >= 1000 && value <= 2000 }
x.report('include?') { (1000..2000).include?(value) }
x.report('between?') { value.between?(1000, 2000) }
x.compare!
end
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin19]
$ ruby bench.rb
Warming up --------------------------------------
>= && <= 2.351M i/100ms
include? 1.139M i/100ms
between? 1.244M i/100ms
Calculating -------------------------------------
>= && <= 23.476M (± 1.3%) i/s - 117.558M in 5.008408s
include? 11.117M (± 8.2%) i/s - 55.807M in 5.057945s
between? 11.021M (± 6.8%) i/s - 55.959M in 5.102033s
Comparison:
>= && <=: 23475928.0 i/s
include?: 11117073.1 i/s - 2.11x slower
between?: 11020978.6 i/s - 2.13x slower
- 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 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
All issues in fastruby/fast-ruby
Similar issues
-
SyncEm always forwards a dummy block, so wrapped methods lose their no-block/Enumerator behavior Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
dependabot
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
githubnext/gh-aw-cao#13349 ·
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·