Given
## the following two (here three) lines are all of fasttime's R/time.R
fastPOSIXct <- function(x, tz=NULL, required.components = 3L)
.POSIXct(if (is.character(x)) .Call("parse_ts", x, required.components)
else .Call("parse_ts", as.character(x), required.components), tz)
hence
## so we suggest to just use it, and convert later
fastDate <- function(x, tz=NULL)
as.Date(fastPOSIXct(x, tz=tz))
which at least beats as.Date()
:
R> library(microbenchmark)
R> library(fasttime)
R> d <- rep("2010-11-12", n=1e4)
R> microbenchmark(fastDate(d), as.Date(d), times=100)
Unit: microseconds
expr min lq mean median uq max neval cld
fastDate(d) 47.469 48.8605 54.3232 55.7270 57.1675 104.447 100 a
as.Date(d) 77.194 79.4120 85.3020 85.2585 87.3135 121.979 100 b
R>
If you wanted to go super fast, you could start with tparse.c to create the date-only subset you want.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…