Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:04:31+00:00 2026-06-04T05:04:31+00:00

As the title goes. Why is the lubridate function so much slower? library(lubridate) library(microbenchmark)

  • 0

As the title goes. Why is the lubridate function so much slower?

library(lubridate)
library(microbenchmark)

Dates <- sample(c(dates = format(seq(ISOdate(2010,1,1), by='day', length=365), format='%d-%m-%Y')), 50000, replace = TRUE)

microbenchmark(as.POSIXct(Dates, format = "%d-%b-%Y %H:%M:%S", tz = "GMT"), times = 100)
microbenchmark(dmy(Dates, tz ="GMT"), times = 100)

Unit: milliseconds
expr                                                            min         lq          median      uq          max
1 as.POSIXct(Dates, format = "%d-%b-%Y %H:%M:%S", tz = "GMT")   103.1902    104.3247    108.675     109.2632    149.871
2 dmy(Dates, tz = "GMT")                                        184.4871    194.1504    197.8422    214.3771    268.4911
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:04:33+00:00Added an answer on June 4, 2026 at 5:04 am

    For the same reason cars are slow in comparison to riding on top of rockets. The added ease of use and safety make cars much slower than a rocket but you’re less likely to get blown up and it’s easier to start, steer, and brake a car. However, in the right situation (e.g., I need to get to the moon) the rocket is the right tool for the job. Now if someone invented a car with a rocket strapped to the roof we’d have something.

    Start with looking at what dmy is doing and you’ll see the difference for the speed (by the way from your bechmarks I wouldn’t say that lubridate is that much slower as these are in milliseconds):

    dmy #type this into the command line and you get:

    >dmy
    function (..., quiet = FALSE, tz = "UTC") 
    {
        dates <- unlist(list(...))
        parse_date(num_to_date(dates), make_format("dmy"), quiet = quiet, 
            tz = tz)
    }
    <environment: namespace:lubridate>
    

    Right away I see parse_date and num_to_date and make_format. Makes one wonder what all these guys are. Let’s see:

    parse_date

    > parse_date
    function (x, formats, quiet = FALSE, seps = find_separator(x), 
        tz = "UTC") 
    {
        fmt <- guess_format(head(x, 100), formats, seps, quiet)
        parsed <- as.POSIXct(strptime(x, fmt, tz = tz))
        if (length(x) > 2 & !quiet) 
            message("Using date format ", fmt, ".")
        failed <- sum(is.na(parsed)) - sum(is.na(x))
        if (failed > 0) {
            message(failed, " failed to parse.")
        }
        parsed
    }
    <environment: namespace:lubridate>
    

    num_to_date

    > getAnywhere(num_to_date)
    A single object matching ‘num_to_date’ was found
    It was found in the following places
      namespace:lubridate
    with value
    
    function (x) 
    {
        if (is.numeric(x)) {
            x <- as.character(x)
            x <- paste(ifelse(nchar(x)%%2 == 1, "0", ""), x, sep = "")
        }
        x
    }
    <environment: namespace:lubridate>
    

    make_format

    > getAnywhere(make_format)
    A single object matching ‘make_format’ was found
    It was found in the following places
      namespace:lubridate
    with value
    
    function (order) 
    {
        order <- strsplit(order, "")[[1]]
        formats <- list(d = "%d", m = c("%m", "%b"), y = c("%y", 
            "%Y"))[order]
        grid <- expand.grid(formats, KEEP.OUT.ATTRS = FALSE, stringsAsFactors = FALSE)
        lapply(1:nrow(grid), function(i) unname(unlist(grid[i, ])))
    }
    <environment: namespace:lubridate>
    

    Wow we got strsplit-ting, expand-ing.grid-s, paste-ing, ifelse-ing, unname-ing etc. plus a Whole Lotta Error Checking Going On (play on the Zep song). So what we have here is some nice syntactic sugar. Mmmmm tasty but it comes with a price, speed.

    Compare that to as.POSIXct:

    getAnywhere(as.POSIXct)  #tells us to use methods to see the business
    methods('as.POSIXct')    #tells us all the business
    as.POSIXct.date          #what I believe your code is using (I don't use dates though)
    

    There’s a lot more Internal coding and less error checking going on with as.POSIXct So you have to ask do I want ease and safety or speed and power? Depends on the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title goes I am trying something like $(ul li:nth-child(' + xx +
Alright, hard to phrase an exact title for this question, but here goes... I
OK, I don't think the title says it right... but here goes: I have
Title pretty much sums it up. Is there a technical name given to a
Title pretty much says it all. The web.config, unchanged from how VS2008SP1 generated it,
I have the following string: h3. My Title Goes Here I basically want to
On a webpage, I have markup like the following: <h3>Title Goes here</h3> <a href=...>Link
Title pretty much covers it. If I've added say 3 objects to a list
Just as the title goes. I have a python program which processes some data
Just as the title goes. Or will it invoked on the first run of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.