-
Notifications
You must be signed in to change notification settings - Fork 186
Avoid paste0 overhead in is_lint_level #2360
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2360 +/- ##
==========================================
- Coverage 99.13% 99.13% -0.01%
==========================================
Files 124 124
Lines 5574 5573 -1
==========================================
- Hits 5526 5525 -1
Misses 48 48 ☔ View full report in Codecov by Sentry. |
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.
Can you benchmark switch()
vs. if()
first?
I had done a quick benchmarking locally that I am producing here, but not sure if you are actually looking for benchmark for level <- "expression"
bench::mark(
"if" = paste0(if (level == "file") "full_", "parsed_content"),
"switch" = switch(level,
file = "full_parsed_content",
expression = "parsed_content"
),
iterations = 1000,
time_unit = "us"
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <dbl> <dbl> <dbl> <bch:byt> <dbl>
#> 1 if 0.902 0.984 881984. 0B 0
#> 2 switch 0 0.0410 21351784. 0B 0 Created on 2023-11-28 with reprex v2.0.2 |
I was thinking |
Ah, I see. Here it is: level <- "expression"
bench::mark(
"if" = if (level == "file") "full_parsed_content" else "parsed_content",
"switch" = switch(level,
file = "full_parsed_content",
expression = "parsed_content"
),
iterations = 1000,
time_unit = "us"
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <dbl> <dbl> <dbl> <bch:byt> <dbl>
#> 1 if 0.0410 0.0820 6850171. 0B 0
#> 2 switch 0 0.0410 19969240. 0B 0 Created on 2023-11-28 with reprex v2.0.2 |
On a computer now, could check,' level <- "expression"
bench::mark(
"if" = if (level == "expression") "parsed_content" else "full_parsed_content",
"switch" = switch(level,
file = "full_parsed_content",
expression = "parsed_content"
)
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 if 120ns 128ns 6010347. 0B 0
#> 2 switch 76ns 83ns 9321876. 0B 0
level <- "file"
bench::mark(
"if" = if (level == "expression") "parsed_content" else "full_parsed_content",
"switch" = switch(level,
file = "full_parsed_content",
expression = "parsed_content"
)
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 if 123.1ns 132.1ns 6368058. 0B 0
#> 2 switch 68.9ns 75.1ns 10365642. 0B 0 Created on 2023-11-28 with reprex v2.0.2 |
Here are some larger benchmarks: expression
file
|
Closes #2358