mhahsler / dbscan

Density Based Clustering of Applications with Noise (DBSCAN) and Related Algorithms - R package
GNU General Public License v3.0
314 stars 64 forks source link

refactor: use seq_along and seq_len #72

Closed m-muecke closed 4 months ago

m-muecke commented 4 months ago

Use safer (0 edge case) and slightly faster seq_along(x), seq_len(nrow(x)), seq_along(ncol(x))

x <- rnorm(100)
bench::mark(1:length(x), seq_along(x))
#> # A tibble: 2 × 6
#>   expression        min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>   <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 1:length(x)         0     41ns  9200446.        0B        0
#> 2 seq_along(x)        0      1ns 27803363.        0B        0

Created on 2024-07-12 with reprex v2.1.1