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

Replace if with multiple comparison with case #274

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

tagliala
Copy link
Member

Replace if statements with a case statement to address Style/MultipleComparison offense. This change improves performance by speeding up execution in most cases, with a slight trade-off in speed for :now checks.

The majority of spec suite cases involve the current date, making this optimization beneficial.

Comparison (:now):
           if...else: 14708814.2 i/s
                case: 13579441.0 i/s - 1.08x  (± 0.00) slower

Comparison (:today):
                case: 14638473.0 i/s
           if...else: 13331314.1 i/s - 1.10x  (± 0.00) slower

Comparison (else):
                case: 14111134.0 i/s
           if...else: 12212282.1 i/s - 1.16x  (± 0.00) slower

Replace `if` statements with a `case` statement to address
`Style/MultipleComparison` offense. This change improves performance by
speeding up execution in most cases, with a slight trade-off in speed
for `:now` checks.

The majority of spec suite cases involve the current date, making this
optimization beneficial.

```
Comparison (now):
           if...else: 14708814.2 i/s
                case: 13579441.0 i/s - 1.08x  (± 0.00) slower

Comparison (today):
                case: 14638473.0 i/s
           if...else: 13331314.1 i/s - 1.10x  (± 0.00) slower

Comparison (else):
                case: 14111134.0 i/s
           if...else: 12212282.1 i/s - 1.16x  (± 0.00) slower
```
@tagliala tagliala merged commit 7bb535e into master Mar 29, 2024
10 of 14 checks passed
@tagliala tagliala deleted the chore/switch-to-case-statement branch March 29, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant