-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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 0But I do suspect numr_substitute() is more robust to e.g. character encoding and locale issues.
Metadata
Metadata
Assignees
Labels
No labels