Skip to content

Instantly share code, notes, and snippets.

@paleolimbot
Last active April 27, 2020 13:23
Show Gist options
  • Save paleolimbot/308173d9ae7ad8a74edb0f47b69a696c to your computer and use it in GitHub Desktop.
Save paleolimbot/308173d9ae7ad8a74edb0f47b69a696c to your computer and use it in GitHub Desktop.
nc_wkb <- geovctrs::geo_nc$geometry
nc_WKB <- nc_wkb
class(nc_WKB) <- "WKB"
nc_sfc <- sf::st_as_sfc(nc_WKB, EWKB = TRUE)
nc_sp <- sf::as_Spatial(nc_sfc)
wkt_ptype <- geovctrs::geo_wkt()
wkb_ptype <- geovctrs::geo_wkb()
bench::mark(
wk:::wkb_translate_wkt(nc_wkb),
geovctrs:::geovctrs_cpp_convert(nc_wkb, wkt_ptype),
sf:::st_as_text.sfc(sf:::st_as_sfc.WKB(nc_WKB, EWKB = TRUE)),
check = FALSE
)
bench::mark(
wk:::wkb_translate_wkb(nc_wkb),
geovctrs:::geovctrs_cpp_convert(nc_wkb, wkb_ptype),
sf_wkb_read_write = sf:::CPL_read_wkb(sf:::CPL_write_wkb(nc_sfc, EWKB = TRUE), EWKB = TRUE),
wkb_read_write = wkb::readWKB(wkb::writeWKB(nc_sp)),
check = FALSE
)
@paleolimbot
Copy link
Author

nc_wkb <- geovctrs::geo_nc$geometry
nc_WKB <- nc_wkb
class(nc_WKB) <- "WKB"
nc_sfc <- sf::st_as_sfc(nc_WKB, EWKB = TRUE)
wkt_ptype <- geovctrs::geo_wkt()
wkb_ptype <- geovctrs::geo_wkb()

bench::mark(
  wk:::wkb_translate_wkt(nc_wkb),
  geovctrs:::geovctrs_cpp_convert(nc_wkb, wkt_ptype),
  sf:::st_as_text.sfc(sf:::st_as_sfc.WKB(nc_WKB, EWKB = TRUE)),
  check = FALSE
)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 3 x 6
#>   expression                                                        min
#>   <bch:expr>                                                   <bch:tm>
#> 1 wk:::wkb_translate_wkt(nc_wkb)                                 3.02ms
#> 2 geovctrs:::geovctrs_cpp_convert(nc_wkb, wkt_ptype)             3.94ms
#> 3 sf:::st_as_text.sfc(sf:::st_as_sfc.WKB(nc_WKB, EWKB = TRUE)) 170.62ms
#> # … with 4 more variables: median <bch:tm>, `itr/sec` <dbl>,
#> #   mem_alloc <bch:byt>, `gc/sec` <dbl>

bench::mark(
  wk:::wkb_translate_wkb(nc_wkb),
  geovctrs:::geovctrs_cpp_convert(nc_wkb, wkb_ptype),
  sf_wkb_read_write = sf:::CPL_read_wkb(sf:::CPL_write_wkb(nc_sfc, EWKB = TRUE), EWKB = TRUE),
  check = FALSE
)
#> # A tibble: 3 x 6
#>   expression                                           min median `itr/sec`
#>   <bch:expr>                                         <bch> <bch:>     <dbl>
#> 1 wk:::wkb_translate_wkb(nc_wkb)                     120µs  141µs     6905.
#> 2 geovctrs:::geovctrs_cpp_convert(nc_wkb, wkb_ptype) 526µs  565µs     1725.
#> 3 sf_wkb_read_write                                  385µs  420µs     2302.
#> # … with 2 more variables: mem_alloc <bch:byt>, `gc/sec` <dbl>

Created on 2020-04-26 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment