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 6571575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:53:59+00:00 2026-05-25T14:53:59+00:00

I just realized that for a POSIX variable with two decimal places the following

  • 0

I just realized that for a POSIX variable with two decimal places the following function successor() shows significant performance loss. Besides that the for loop might not be good r-style*. I was surprised that on my system POSIX with two decimals is nearly 30 times slower (20000 steps) than POSIX without decimals. POSIX with decimals is even slower than just storing the vector as character.

So is the slow performance just because of the successor() function? Or is it in general more advice able in R to store Time/Date variables as characters and just convert it when really needed?

successor <- function(z) {
y<-as.vector(z)
for(i in 1:NROW(z)) {
y[i] <- if(i == NROW(z)) NA else z[i+1]
}
return(y)
}

u<-rep(strptime("15.01.2010 10:21:52.85",format="%d.%m.%Y %H:%M:%OS"),20000) # fragments of seconds stored
v<-seq(c(ISOdate(2011,09,12)),by="min", length.out=20000) # no fragments of seconds saved
u.posix.time.small<-system.time(successor(u[1:1000]))
u.char.time.small<-system.time(successor(as.character(u[1:1000])))
u.posix.time.big<-system.time(successor(u[1:20000]))
u.char.time.big<-system.time(successor(as.character(u[1:20000])))

v.posix.time.small<-system.time(successor(v[1:1000]))
v.char.time.small<-system.time(successor(as.character(v[1:1000])))
v.posix.time.big<-system.time(successor(v[1:20000]))
v.char.time.big<-system.time(successor(as.character(v[1:20000])))
rbind(u.posix.time.small,u.posix.time.big,u.char.time.small, u.char.time.big,v.posix.time.small, v.posix.time.big, v.char.time.small,v.char.time.big)[,1:3]

*I came across the predecessor/sucessor thing when using segments(x0=x[i],x1=x[i+1], y0=y[i], y1=y[i+1]) in plot. Anyway I guess there must be another way to address the successors/predecessors since storing the values twice seems to me waste. But I am not a programmer just user.

  • 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-05-25T14:54:00+00:00Added an answer on May 25, 2026 at 2:54 pm

    In your example, u is class POSIXlt while v is class POSIXct. If you convert u to POSIXct, the timings are very similar.

    POSIXlt objects are less efficient because they’re stored as a list of vectors, whereas POSIXct objects are stored as a single numeric vector.

    > u <- as.POSIXct(u)
    > u.posix.time.small<-system.time(successor(u[1:1000]))
    > u.char.time.small<-system.time(successor(as.character(u[1:1000])))
    > u.posix.time.big<-system.time(successor(u[1:20000]))
    > u.char.time.big<-system.time(successor(as.character(u[1:20000])))
    > rbind(u.posix.time.small,u.posix.time.big,u.char.time.small, u.char.time.big,
    + v.posix.time.small, v.posix.time.big, v.char.time.small,v.char.time.big)[,1:3]
                       user.self sys.self elapsed
    u.posix.time.small      0.04     0.00    0.04
    u.posix.time.big        1.91     0.01    1.92
    u.char.time.small       0.01     0.00    0.02
    u.char.time.big         0.29     0.02    0.32
    v.posix.time.small      0.05     0.00    0.04
    v.posix.time.big        1.43     0.00    1.44
    v.char.time.small       0.02     0.00    0.01
    v.char.time.big         0.32     0.00    0.32
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just realized that I need to synchronize a significant amount of data collection
I just realized that you can't just use an if statement on a function,
I just realized that in some place in my code I have the return
I just realized from an article in CACM that Doxygen works with Java (and
I just realised that Office 2007 now shows multiple pages per default. I can
Just realized that the delegates I am declaring are not declared with pointer type.
I just realized that TextReader, the type of Console.In, doesn't have a BeginRead-method. How
I just realized that I lack the fundamental knowledge of what exactly happens as
I just realized that DBUnit doesn't create tables by itself (see How do I
I just realized that I am supposed to include the #include<cstdlib> required by abs()

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.