Coder Social home page Coder Social logo

Comments (3)

Robinlovelace avatar Robinlovelace commented on May 25, 2024

Relevant PR: https://github.com/cyclestreets/cyclestreets-r/pull/45/files

from cyclestreets-r.

Robinlovelace avatar Robinlovelace commented on May 25, 2024

Code in most recent commit linked to above shows that it is ~2x quicker.

> fromPlace = sf::st_as_sf(lwgeom::st_startpoint(od))
> toPlace = sf::st_as_sf(lwgeom::st_endpoint(od))
> library(sf)
> bench::mark(check = FALSE, max_iterations = 1,
+             journey = (r1 <<- route(l = od, route_fun = journey, plan = "quietest")),
+             journey2 = (r2 <<- journey2(fromPlace, toPlace, id = od$route_id, plan = "quietest", segments = TRUE))
+             )
# A tibble: 2 × 13
  expression      min   median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result memory     time       gc      
  <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list> <list>     <list>     <list>  
1 journey       9.16s    9.16s     0.109    20.8MB    0.328     1     3      9.16s <NULL> <Rprofmem> <bench_tm> <tibble>
2 journey2      4.73s    4.73s     0.211    24.4MB    0.423     1     2      4.73s <NULL> <Rprofmem> <bench_tm> <tibble>
Warning message:
Some expressions had a GC in every iteration; so filtering is disabled. 

from cyclestreets-r.

Robinlovelace avatar Robinlovelace commented on May 25, 2024

Quick win to speed-up reading:

cyclestreets-r/R/journey.R

Lines 306 to 325 in 9449bec

vals_variable$elevation_mean = stringr::str_split(vals_variable$elevations, pattern = ",") %>%
lapply(as.numeric) %>%
lapply(mean) %>%
unlist()
vals_variable$elevation_start = stringr::str_split(vals_variable$elevations, pattern = ",") %>%
lapply(as.numeric) %>%
lapply(utils::head, 1) %>%
unlist()
vals_variable$elevation_end = stringr::str_split(vals_variable$elevations, pattern = ",") %>%
lapply(as.numeric) %>%
lapply(utils::tail, 1) %>%
unlist()
vals_variable$elevation_max = stringr::str_split(vals_variable$elevations, pattern = ",") %>%
lapply(as.numeric) %>%
lapply(max) %>%
unlist()
vals_variable$elevation_min = stringr::str_split(vals_variable$elevations, pattern = ",") %>%
lapply(as.numeric) %>%
lapply(min) %>%
unlist()

from cyclestreets-r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.