Skip to content

Conversation

@nobu
Copy link
Member

@nobu nobu commented Sep 15, 2023

Empty ranges do not overlap with any range.

Regarding benchmarks, #8242 is significantly faster in some cases, but one of these two cases is a wrong result.

ActiveSupport PR#8242 built-ruby
(2..3).overlap?(1..1) 7.761M 15.053M 32.368M
- 1.94x 4.17x
(2..3).overlap?(2..4) 25.720M 55.070M 21.981M
1.17x 2.51x -
(2..3).overlap?(4..5) 7.616M 15.048M 21.730M
- 1.98x 2.85x
(2..3).overlap?(2..1) 25.585M 56.545M 32.786M
- 2.21x 1.28x
(2..3).overlap?(0..1) 7.554M 14.755M 32.545M
- 1.95x 4.31x
(2..3).overlap?(...1) 6.681M 5.843M 32.255M
1.14x - 5.52x
(2...3).overlap?(..2) 6.676M 5.817M 21.572M
1.15x - 3.71x
(2...3).overlap?(3...) 7.392M 14.755M 31.805M
- 2.00x 4.30x
(2..3).overlap?('a'..'d') 3.675M 3.482M 17.009M
1.06x - 4.89x
Empty ranges do not overlap with any range. Regarding benchmarks, PR#8242 is significantly faster in some cases, but one of these two cases is a wrong result. | |ActiveSupport| PR#8242|built-ruby| |:--------------------------|------------:|-------:|---------:| |(2..3).overlap?(1..1) | 7.761M| 15.053M| 32.368M| | | -| 1.94x| 4.17x| |(2..3).overlap?(2..4) | 25.720M| 55.070M| 21.981M| | | 1.17x| 2.51x| -| |(2..3).overlap?(4..5) | 7.616M| 15.048M| 21.730M| | | -| 1.98x| 2.85x| |(2..3).overlap?(2..1) | 25.585M| 56.545M| 32.786M| | | -| 2.21x| 1.28x| |(2..3).overlap?(0..1) | 7.554M| 14.755M| 32.545M| | | -| 1.95x| 4.31x| |(2..3).overlap?(...1) | 6.681M| 5.843M| 32.255M| | | 1.14x| -| 5.52x| |(2...3).overlap?(..2) | 6.676M| 5.817M| 21.572M| | | 1.15x| -| 3.71x| |(2...3).overlap?(3...) | 7.392M| 14.755M| 31.805M| | | -| 2.00x| 4.30x| |(2..3).overlap?('a'..'d') | 3.675M| 3.482M| 17.009M| | | 1.06x| -| 4.89x|
@nobu nobu changed the title [Feature #19839] Add Range#overlap? [Feature #19839] Fix Range#overlap? on empty ranges Sep 16, 2023
@nobu nobu changed the title [Feature #19839] Fix Range#overlap? on empty ranges [Feature #19839] Fix Range#overlap? for empty ranges Sep 16, 2023
@nobu nobu merged commit b4213a7 into ruby:master Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant