MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: AbsoluteTime[] runs slowly?

  • To: mathgroup at
  • Subject: [mg122338] Re: AbsoluteTime[] runs slowly?
  • From: David Bailey <dave at>
  • Date: Tue, 25 Oct 2011 06:19:55 -0400 (EDT)
  • Delivered-to:
  • References: <j80qge$af2$>

On 23/10/2011 11:32, Robert McHugh wrote:
> The following code takes over a minute to run on my machine.  Is this expected behavior?
> t = {"14-May-10 09:58:05", {"Day", "-", "MonthNameShort", "-", "YearShort", " ", "Hour", ":", "Minute", ":", "Second"}};
> tList = Table[t, {i, 100000}];
> a = Timing[AbsoluteTime[#]&  /@ tList ;]
> For reference, an operation like the following takes less than a tenth of a second. (Of course this second example needs quite a bit of modification to provide a correct answer, but it does show how fast the program can operate on a large list.)
> t = {14, 5, 10, 9, 58, 05};
> tList = Table[t, {i, 100000}];
> a = Timing[( ((#[[3]] 0 + #[[2]] 30 + #[[1]]24) + #[[4]]) 60 + #[[5]]) 60 + #[[6]]&  /@ tList;]
> Some background: am analyzing some historical data (about 500 000 records, one data point a minute for about a year) and am making a few utilities to retrieve the data for any given time interval.   My original plan was to change the time stamp to absolute time and then use a select statement.  This step in the above example, changing the time stamps to absolute time, is the rate limiting step in the code (everything else runs in about 5 seconds).
> Was wondering if someone could explain why AbsoluteTime[] is relatively slow operation and perhaps some faster operations for date and time comparisons.
> Thanks
As an experiment, I replaced AbsoluteTime[#] by AbsoluteTime[], and that 
ran very fast. I suspect that variant of AbsoluteTime is not often used 
- at least intensively, and has not been coded efficiently!

Are your records held in memory as an array? If they are, and if there 
are no gaps or non-uniformities in the record, why not access the array 
using Part? This will be vastly more efficient than using Select repeatedly.

David Bailey

  • Prev by Date: language settings for date functions
  • Next by Date: still struggling about integration
  • Previous by thread: Re: AbsoluteTime[] runs slowly?
  • Next by thread: Re: Using colored text in PlotLabel