Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5837
| From | Armand Tamzarian <mike.honeychurch@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: AbsoluteTime[] runs slowly? |
| Date | 2011-10-24 09:18 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j83ah2$k5j$1@smc.vnet.net> (permalink) |
| References | <j80qge$af2$1@smc.vnet.net> |
On Oct 23, 9:32 pm, Robert McHugh <bob_mchugh_2...@yahoo.com> 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
If your data is regularly spaced at fixed one minute intervals then
just create a list of absolute times directly rather than via a
conversion:
e.g.
startDate = AbsoluteTime[{2010, 1, 1}]
endDate = AbsoluteTime[{2011, 12, 31}]
listofTimes = Range[startDate, endDate, 60]
Once you have your list you can transpose it with your data.
newData=Transpose[{listofTimes, yourData}]
You can then use Select or Cases if you want to pick out chunks in
particular time ranges.
An alternative would be to stick your data in a SQL database and use
the DatabaseLink and call date/time ranges via SQL. That is probably
the option I would use.
Mike
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
AbsoluteTime[] runs slowly? Robert McHugh <bob_mchugh_2000@yahoo.com> - 2011-10-23 10:32 +0000 Re: AbsoluteTime[] runs slowly? Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-10-24 09:18 +0000 Re: AbsoluteTime[] runs slowly? David Bailey <dave@removedbailey.co.uk> - 2011-10-25 10:27 +0000
csiph-web