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

numr_replace() or numr_substitute()? #10

Open
joeroe opened this issue Feb 8, 2021 · 0 comments
Open

numr_replace() or numr_substitute()? #10

joeroe opened this issue Feb 8, 2021 · 0 comments

Comments

@joeroe
Copy link
Owner

joeroe commented Feb 8, 2021

Which to use as the default for formatting numerals? numr_replace() uses string replacement; numr_substitute() decomposes a numeric into digits and directly subsets the numerals matrix.

I was hoping numr_substitute() would be faster, but it isn't (yet):

library("numerals")

x <- floor(runif(1000) * 1e6)

bench::mark(
  numr_substitute(x, "fa")
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 1 x 6
#>   expression                    min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>               <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 numr_substitute(x, "fa")   18.9ms     21ms      45.2        NA     68.7

bench::mark(
  numr_replace(x, "fa")
)
#> # A tibble: 1 x 6
#>   expression                 min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>            <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 numr_replace(x, "fa")   8.51ms   8.54ms      112.        NA        0

But I do suspect numr_substitute() is more robust to e.g. character encoding and locale issues.

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

1 participant