Closed rafapereirabr closed 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
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)] })
gtfstools::string_to_seconds()