lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
362 stars 59 forks source link

Minor speed improvement #390

Closed etiennebacher closed 5 months ago

etiennebacher commented 1 year ago

Minor improvement: use tabulate() instead of table().

table() returns a named vector and tabulate() returns an unnamed vector, but that doesn't matter here because you remove the names anyway:

set.seed(123)
foo <- sample(1:100, 1e7, TRUE)
bench::mark(
    tabulate(foo),
    table(foo),
    iterations = 20,
    check = FALSE
)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 2 × 6
#>   expression         min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>    <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 tabulate(foo)   12.5ms   13.5ms     72.9     12.8KB     0   
#> 2 table(foo)     551.6ms  649.4ms      1.54   662.2MB     7.86

Created on 2023-02-22 with reprex v2.0.2

I ran the tests locally and everything looked fine.

etiennebacher commented 5 months ago

There a bunch of conflicts now and I don't want to resolve them as the change is very simple so I'm closing this

lrberge commented 5 months ago

Very sorry Etienne for the huge delay. It's that I had to check it was OK. It indeed was and it was trivial to check, sorry. Now I added your change in the package, thanks.

etiennebacher commented 5 months ago

No worries at all, I can't imagine the amount of work behind this package, and it's completely fine to prioritize academic projects (among other things). Thanks once again for this package, it's so convenient and nice to use