Skip to content
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

speed up conversion to IDateTime #1392

Closed
jangorecki opened this issue Oct 12, 2015 · 1 comment
Closed

speed up conversion to IDateTime #1392

jangorecki opened this issue Oct 12, 2015 · 1 comment
Assignees
Milestone

Comments

@jangorecki
Copy link
Member

@jangorecki jangorecki commented Oct 12, 2015

Conversion of POSIXct to IDate and ITime is likely to be bottleneck. I see some place for improvement to handle POSIXct directly, not using POSIXlt as it is now.
Below some timings

install.packages("microbenchmarkCore", repos = paste0("https://",c(
    "olafmersmann.github.io/drat"
)))
library(microbenchmarkCore)
library(data.table)
x = as.POSIXct(1:1e7, origin="1970-01-01")
str(x)
# POSIXct[1:10000000], format: "1970-01-01 00:00:01" "1970-01-01 00:00:02" "1970-01-01 00:00:03" "1970-01-01 00:00:04" "1970-01-01 00:00:05" "1970-01-01 00:00:06" ...
as.ITimeNew = function(x){
    structure(as.integer(x) %% 86400, class = "ITime")
}
system.nanotime(
    r_current <- as.ITime(x)
)
#      user    system   elapsed 
#        NA        NA 0.7089193
system.nanotime(
    r_new <- as.ITimeNew(x)
)
#      user    system   elapsed 
#        NA        NA 0.2976062
all.equal(r_current, r_new)
# [1] TRUE
microbenchmark(times=5L,
               as.ITime(x),
               as.ITimeNew(x))
# Unit: milliseconds
#            expr      min       lq     mean   median       uq      max neval
#     as.ITime(x) 705.9513 719.4441 719.6274 723.1317 724.5856 725.0242     5
#  as.ITimeNew(x) 293.5473 293.6914 306.8225 300.4021 313.9687 332.5033     5
@jangorecki jangorecki changed the title speed up IDateTime speed up conversion to IDateTime Oct 12, 2015
@jangorecki jangorecki self-assigned this Nov 23, 2016
@jangorecki jangorecki added this to the v1.9.10 milestone Nov 23, 2016
@MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented May 24, 2017

Related: #2156, #1383

@mattdowle mattdowle added this to the v1.10.6 milestone Aug 8, 2017
@mattdowle mattdowle removed this from the Candidate milestone Aug 8, 2017
@mattdowle mattdowle added this to the Candidate milestone Aug 8, 2017
@mattdowle mattdowle removed this from the v1.10.6 milestone Aug 8, 2017
@mattdowle mattdowle removed this from the Candidate milestone Oct 13, 2017
@mattdowle mattdowle added this to the v1.10.6 milestone Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants