1
$\begingroup$

I'm doing simple data analysis, where I load some "date-time" data from a file. The data is a simple list, but there are 41,000 values in total. Here's a short sample:

"26.11.2014 13:56:17" "26.11.2014 13:56:18" "26.11.2014 13:56:20"

Here is my code, which extracts a list of date-times from a file and transform the results into list of seconds (integers):

l = Import["c:\\tmp\\1.csv", "List"];   
l2 = AbsoluteTime /@ l;

The problem is that it takes about 15 seconds and 100% of a CPU core to do the step 2 (AbsoluteTime) for a mere 41k elements.

Are there ways to speed up this operation?

Maybe Import into a list of Dates, not into a generic list? Or should I change the strategy altogether and prepare data before loading into the Mathematica?

$\endgroup$
0
2
$\begingroup$
l = ConstantArray[{"26.11.2014 13:56:17", "26.11.2014 13:56:18" , 
                   "26.11.2014 13:56:20"}, {10000}] // Flatten;

I can get 20x speed up by converting it to DateList form:

AbsoluteTime[
  ToExpression@StringSplit[#, " " | "." | ":"][[{3, 2, 1, 4, 5, 6}]] 
  ]& /@  l; // Timing
{1.684811, Null}
$\endgroup$
2
  • $\begingroup$ 0 down vote accept I got 15x with this feat. Thanks. $\endgroup$ – Ilya Sorokin Nov 30 '14 at 14:08
  • $\begingroup$ @IlyaSorokin what do you mean by 0 down vote accept? :) p.s. please take a tour $\endgroup$ – Kuba Dec 1 '14 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.