-
Notifications
You must be signed in to change notification settings - Fork 7
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
Optimize wk_coords()
for sfc objects
#138
Comments
This probably just applies to sfc_POINT, sfc_LINESTRING, and SFC_MULTIPOINT. For any greater level of nesting, the cost of sf's approach appears to be greater than the cost of wk's approach. library(wk)
points <- xy(runif(1e5), runif(1e5))
points_sfc <- sf::st_as_sfc(points)
bench::mark(
wk::wk_coords(points_sfc),
sf::st_coordinates(points_sfc),
check = F
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 wk::wk_coords(points_sfc) 4.69ms 4.92ms 201. 4.26MB 26.4
#> 2 sf::st_coordinates(points_sfc) 1.07ms 1.22ms 819. 3.07MB 99.1
points2 <- xy(runif(1e6), runif(1e6))
linestrings_wkb <- wk_linestring(points2, rep(1:1e2, each = 1e3))
linestrings_sfc <- sf::st_as_sfc(linestrings_wkb)
bench::mark(
wk::wk_coords(linestrings_sfc),
sf::st_coordinates(linestrings_sfc),
check = F
)
#> 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:> <bch:> <dbl> <bch:byt> <dbl>
#> 1 wk::wk_coords(linestrings_sfc) 18.3ms 21.5ms 36.0 130MB 51.2
#> 2 sf::st_coordinates(linestrings_sfc) 10.3ms 11.2ms 83.0 42MB 31.6
points2 <- xy(runif(1e6), runif(1e6))
polygons_wkb <- wk_polygon(points2, rep(1:1e2, each = 1e3))
polygons_sfc <- sf::st_as_sfc(polygons_wkb)
bench::mark(
wk::wk_coords(polygons_sfc),
sf::st_coordinates(polygons_sfc),
check = F
)
#> 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:t> <dbl> <bch:byt> <dbl>
#> 1 wk::wk_coords(polygons_sfc) 18.3ms 20.8ms 32.1 130.1MB 51.0
#> 2 sf::st_coordinates(polygons_sfc) 24.8ms 29.8ms 28.6 99.4MB 22.9 Created on 2022-09-17 by the reprex package (v2.0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: