Re: why DateListPlot is so slow?

• To: mathgroup at smc.vnet.net
• Subject: [mg79948] Re: why DateListPlot is so slow?
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Thu, 9 Aug 2007 05:24:41 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f9c0ae\$5o4\$1@smc.vnet.net>

```Arkadiusz.Majka at gmail.com wrote:
> Hi,
>
> I have a list (a time series):
>
> data={{00:00:30,x1},{00:01:00,x2},{00:01:30,x3},....}
>
> at equally spaced time intervals (30 seconds). The length od data is
> 8100 (24 h)
>
> DateListPlot[data] works fine but takes 28 sec, since
> ListPlot[data[[All,2]]] does it in less than 0.1 sec....
>
> Can you explain me why DateListPlot is so time consuming? Can we
> improve it?

Hi Arek,

It seems that the slowness of *DateListPlot* is due to the conversion
process that occurs to set up the date/time in canonical form. First we
generate some random data and compare *DateListPlot* against *ListPlot*.

In[1]:= data = Module[{t = 0},
Table[{DateString[t += 10 + RandomInteger[{-1, 1}], "Time"],
40000. + 10000*Sin[t/20000] + RandomReal[{-100, 100}]},
{8100}]];
Timing[DateListPlot[data]][[1]]
Timing[ListPlot[data[[All, 2]], Axes -> None, Frame -> True,
GridLines -> {Automatic, None}]][[1]]

Out[2]= 33.172

Out[3]= 0.016

My understanding of how *DateListPlot* works is that the function first
converts the date/time data in canonical form, canonical form that must
be in the form {yy, mm, dd, hh, mn, ss}. (The function in charge of the
conversation is set up with the option *DateFunction*.) This seem to be
very time consuming.

In[4]:= Timing[DateList /@ data[[All, 1]]; ][[1]]

Out[4]= 32.11

Now, if we massage first the data and then use *DateListPlot*, the speed
improvement is dramatic (though still not as fast as *ListPlot*).

In[5]:= Timing[data2 = Transpose[{Apply[Join, Transpose[
{Table[{2007, 1, 1}, {Length[data]}],
(ToExpression[StringSplit[#1, ":"]] & ) /@
data[[All, 1]]}],
{1}], data[[All, 2]]}]; ][[1]]
Timing[DateListPlot[data2]][[1]]
%% + %
Timing[ListPlot[data2[[All, 2]], Axes -> None, Frame -> True,
GridLines -> {Automatic, None}]][[1]]

Out[5]= 0.265

Out[6]= 0.672

Out[7]= 0.937

Out[8]= 0.016

In[8]:= \$Version

Out[8]= "6.0 for Microsoft Windows (32-bit) (June 19, 2007)"

--
Jean-Marc

```

• Prev by Date: Re: How to let output data in mathematica note book become data in wordpad.
• Next by Date: Re: Two different packages can not Need[] the same utility package?
• Previous by thread: Re: why DateListPlot is so slow?
• Next by thread: FindRoot migration question