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

Default unit = "relative" not accepted (anymore) in microbenchmark #34

Closed
tappek opened this issue Dec 28, 2021 · 5 comments
Closed

Default unit = "relative" not accepted (anymore) in microbenchmark #34

tappek opened this issue Dec 28, 2021 · 5 comments

Comments

@tappek
Copy link

tappek commented Dec 28, 2021

This used to work
microbenchmark::microbenchmark(TRUE, FALSE, unit = "relative")
but in version 1.4.9 (and maybe the previous version) it errors with:

Error in match.arg(unit, values) : 
  'arg' should be one of “nanoseconds”, “ns”, “microseconds”, “us”, “milliseconds”, “ms”, “seconds”, “s”, “secs”, “time”, “t”, “frequency”, “f”, “hz”, “khz”, “mhz”, “eps”

Could #20 and the associated commit 6533560 be the culprit?

Passing unit = "relative" directly to summary still works.

mb <- microbenchmark::microbenchmark(TRUE, FALSE)
summary(mb, unit = "relative")
@richierocks
Copy link

I just fell over this same issue. The workaround is straightforward, but having to explicitly all print() is not very idiomatic R code.

# This causes an error in recent versions 
microbenchmark(TRUE, FALSE, unit="relative")
#> Error in match.arg(unit, values): 'arg' should be one of "nanoseconds", "ns", "microseconds", "us", "milliseconds", "ms", "seconds", "s", "secs", "time", "t", "frequency", "f", "hz", "khz", "mhz", "eps"

# This is the workaround
res <- microbenchmark(TRUE, FALSE)
print(res, unit="relative")
#> Unit: relative
#>   expr min lq     mean median uq      max neval
#>   TRUE 1.0  1 1.000000      1  1  1.00000   100
#>  FALSE 1.5  1 5.661927      1  1 48.81356   100

@joshuaulrich
Copy link
Owner

Thanks for the report @tappek! And thanks for the bump @richierocks. I just pushed a branch with a potential fix. Please test and report back. Thank you both again!

@joshuaulrich
Copy link
Owner

Hey @tappek and @richierocks, can you please let me know if this branch fixes the issue?
remotes::install_github("joshuaulrich/microbenchmark@34-unit-relative")

@tappek
Copy link
Author

tappek commented May 14, 2022

Works for me! Thank you!

@richierocks
Copy link

Sorry for delayed response. Yes, this works. Thanks for the fix.

olafmersmann pushed a commit to olafmersmann/microbenchmark that referenced this issue Jan 8, 2023
The fix to joshuaulrich#20 did not account for `unit = "relative"`, which broke
existing functionality.

Fixes joshuaulrich#34.
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

No branches or pull requests

3 participants