ipeaGIT / gtfs2gps

Convert GTFS data into a data.table with GPS-like records in R
https://ipeagit.github.io/gtfs2gps/
Other
71 stars 10 forks source link

Check performance of using gtfstools::string_to_seconds() #248

Closed rafapereirabr closed 2 years ago

rafapereirabr commented 2 years ago

gtfstools::string_to_seconds()

pedro-andrade-inpe commented 2 years ago

I think it is not a fair comparison, but for our purpose string_to_seconds() is much faster. The script and results are as follows:


require(gtfs2gps)

getData <- function(){
  sp <-  gtfsio::import_gtfs(system.file("extdata/saopaulo.zip", package = "gtfs2gps"), quiet = TRUE)

  for (i in 1:10)
    sp$stop_times <- rbind(sp$stop_times, sp$stop_times)

  return(sp)
}

sp <- getData()
mysub <- function(value) sub("^24:", "00:", value)

system.time({ sp$stop_times[, departure_time := as.numeric(data.table::as.ITime(mysub(departure_time), format = "%H:%M:%OS"))] })

sp <- getData()

system.time({ gtfstools:::string_to_seconds(sp$stop_times$departure_time) })
> system.time({ sp$stop_times[, departure_time := as.numeric(data.table::as.ITime(mysub(departure_time), format = "%H:%M:%OS"))] })
  usuário   sistema decorrido 
    20.72      0.02     20.89 
> sp <- getData()
> system.time({ gtfstools:::string_to_seconds(sp$stop_times$departure_time) })
  usuário   sistema decorrido 
     1.11      0.05      1.19 
rafapereirabr commented 2 years ago

Thanks, Pedro. Quick note that the call of gtfstools:::string_to_seconds() should be as follows to have a more accurate comparison.

system.time({ sp2$stop_times[, departure_time := gtfstools:::string_to_seconds(departure_time)] })