[Date Index]
[Thread Index]
[Author Index]
Re: runs slowly?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg122313] Re: runs slowly?
*From*: DrMajorBob <btreat1 at austin.rr.com>
*Date*: Mon, 24 Oct 2011 05:16:03 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*References*: <201110231025.GAA10587@smc.vnet.net>
*Reply-to*: drmajorbob at yahoo.com
t = {"14-May-10 09:58:05", {"Day", "-", "MonthNameShort", "-",
"YearShort", " ", "Hour", ":", "Minute", ":", "Second"}};
tList = Table[t, {i, 100000}];
a = Timing[AbsoluteTime[#] & /@ tList;]
{63.1612, Null}
AbsoluteTime is taking about 6 ten thousandths of a second for each call,
which doesn't seem unreasonable... but this is twenty times faster:
t = {2010, 5, 14, 9, 58, 5};
tList = Table[t, {i, 100000}];
a = Timing[AbsoluteTime[#] & /@ tList;]
{3.05313, Null}
...if you could have gotten dates in that format beforehand.
This is ten times faster than the original:
DateString[#, "MonthNameShort"] & /@ Table[{2010, i}, {i, 12}];
twelve = Dispatch@Thread[% -> Range@12];
convert =
ToExpression[
StringSplit[#, {"-", " ", ":"}][[{3, 2, 1, 4, 5, 6}]] /. twelve] &;
t = {"14-May-10 09:58:05", {"Day", "-", "MonthNameShort", "-",
"YearShort", " ", "Hour", ":", "Minute", ":", "Second"}};
tList = Table[t, {i, 100000}];
a = Timing[AbsoluteTime@convert@First@# & /@ tList;]
{6.24957, Null}
You can use "convert" to change all your dates to list format, and then
use AbsoluteTime only when it's needed.
You REALLY don't want to store 100,000 identical copies of {"Day", "-",
"MonthNameShort", "-",
"YearShort", " ", "Hour", ":", "Minute", ":", "Second"}.
Bobby
On Sun, 23 Oct 2011 05:25:28 -0500, Robert McHugh
<bob_mchugh_2000 at 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
>
--
DrMajorBob at yahoo.com
Prev by Date:
**Re: Difficulty with patterns**
Next by Date:
**Re: Difficulty with patterns**
Previous by thread:
**Re: runs slowly?**
Next by thread:
**Re: runs slowly?**
| |