Comments on: Datenum performance https://undocumentedmatlab.com/blog_old/datenum-performance Charting Matlab's unsupported hidden underbelly Wed, 20 May 2020 03:01:17 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Davidhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-382912 Wed, 13 Jul 2016 18:02:51 +0000 http://undocumentedmatlab.com/?p=2299#comment-382912 Yair, sorry for the late response and sorry for your previous experience dealing with APL. Not sure what happened but APL usually has very nice people. On my question and the paid consultation issue…I would if I could but I’m just a engineer and that is way above my pay grade. Anyway, thanks so much.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-381251 Fri, 24 Jun 2016 12:24:03 +0000 http://undocumentedmatlab.com/?p=2299#comment-381251 @David – there is indeed an answer to this but I make it a personal point not to answer any pro-bono questions from JHU-APL following a few cases in previous years where I felt that my goodwill was taken advantage of by your peers. If you want a professional answer to your question then email me for a paid consulting request.

]]>
By: David Longhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-381175 Thu, 23 Jun 2016 19:41:42 +0000 http://undocumentedmatlab.com/?p=2299#comment-381175 Yair, Thanks so much on this. I have a particular problem that using dtstr2dtnummx doesn’t solve, and I was wondering if you knew of a simple fix. You are correct that dtstr2dtnummx is much faster but if you need milliseconds, this doesn’t seem to catch that. For instance, using your code above but adding milliseconds to the time string gives two different results.

tic, 
for i=1:1000 
    dateNum=dtstr2dtnummx({'2010-12-12 12:21:12.123'},'yyyy-MM-dd HH:mm:ss.FFF');
end; 
dateNum
toc
 
dateNum =
          734484.514722222
 
Elapsed time is 0.099181 seconds.
 
% Slower - using datenum
tic
for i=1:1000 
    dateNum=datenum({'2010-12-12 12:21:12.123'},'yyyy-mm-dd HH:MM:SS.FFF');
end; 
dateNum
toc
 
dateNum =
          734484.514723646
 
Elapsed time is 0.172265 seconds.

The difference is the added millisecond value. Even adding the “.FFF” to the format string doesn’t seem to catch the milliseconds in the faster case. This must happen outside of the dtstr2dtnummx function.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-347445 Thu, 02 Apr 2015 09:04:06 +0000 http://undocumentedmatlab.com/?p=2299#comment-347445
which dtstr2dtnummx
]]>
By: Philliphttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-347443 Thu, 02 Apr 2015 09:00:00 +0000 http://undocumentedmatlab.com/?p=2299#comment-347443 Hi

Any idea where dtstr2dtnummx has disappeared to in the newer versions. Can’t find it in 2015a, for example. I know it’s there because I can call it but for the life of me I can’t find it.

Regards,
Phil

]]>
By: JakubThttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-323872 Tue, 29 Apr 2014 08:52:29 +0000 http://undocumentedmatlab.com/?p=2299#comment-323872 Hello,
Mathworks seem to have done some black magic – when I used older Matlab (2011), datenum conversion of a time vector (2.1*10^6 entries) with a given format took 600+ seconds. With DTSTR2DTNUMMX, it took 220 s. In Matlab 2013, it takes 28s only and seems to give a correct answer too!
Best,
Jakub

]]>
By: sprintfc – undocumented helper function | Undocumented Matlabhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-299745 Wed, 27 Nov 2013 20:18:20 +0000 http://undocumentedmatlab.com/?p=2299#comment-299745 […] was the case, for example, of the ismembc function, that I described here back in 2009, and the dtstr2dtnummx function that I described in 2011. Today I describe another such function, sprintfc, based on a tip I […]

]]>
By: datestr performance | Undocumented Matlabhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-58732 Wed, 05 Oct 2011 20:17:34 +0000 http://undocumentedmatlab.com/?p=2299#comment-58732 […] A few months ago, I posted an article showing how we can use some internal help functions to significantly improve the performance […]

]]>
By: Teegeehttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-43265 Wed, 11 May 2011 13:02:48 +0000 http://undocumentedmatlab.com/?p=2299#comment-43265 I have another Tip for such processing. For given vectors, it could save a huge amount of time:

You want to compute the vector A and become the results in the variable Result:

Result=datestr(A); % To avoid

Use the unique function before:

[b, m, n] = unique(A); % Reduce your vector A
b=datestr(b); % Apply your function to b which is much smaller
Result=b(n,:); % Assign it to a vector the same size as A

For a vector A with a lot of same values it saved my life :-)

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-43259 Wed, 11 May 2011 10:20:43 +0000 http://undocumentedmatlab.com/?p=2299#comment-43259 DATENUMMX is still available in the latest Matlab release (R2011a)

]]>
By: Jan Simonhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-43249 Wed, 11 May 2011 08:58:12 +0000 http://undocumentedmatlab.com/?p=2299#comment-43249 Hi,

The built-in DATENUMMX converts [1 x 6] date vectors 4 times faster than DATENUM. It is at least included in Matlab 5.3 to 2009a – I cannot check this in newer versions. As said already, the source code datenummx.c was shipped with Matlab 6.5.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-42706 Thu, 05 May 2011 17:33:04 +0000 http://undocumentedmatlab.com/?p=2299#comment-42706 @Jan – thanks for the tip. I remember being impressed with your datestr2num utility back when, but I simply forgot it lately. So your comment is right on.

In general the basic lesson here, as elsewhere in Matlab, is that wherever we can remove unnecessary input formats, options and validity checks, this could greatly increase the performance.

]]>
By: Datenum performance | Undocumented Matlab | 零度季节https://undocumentedmatlab.com/blog_old/datenum-performance#comment-42651 Thu, 05 May 2011 02:56:57 +0000 http://undocumentedmatlab.com/?p=2299#comment-42651 […] See the article here: Datenum performance | Undocumented Matlab […]

]]>
By: Jan Simonhttps://undocumentedmatlab.com/blog_old/datenum-performance#comment-42624 Wed, 04 May 2011 19:52:31 +0000 http://undocumentedmatlab.com/?p=2299#comment-42624 I’ve published a C-Mex function for the conversion to date numbers: http://www.mathworks.com/matlabcentral/fileexchange/28093-datestr2num
E.g. for the ‘yyyy-mm-dd HH:MM:SS’ format I get these timings (Matlab 2009a, 1.5GHz Pentium-M, 1000 iterations as in your example):

DATENUM: 0.93 sec, DTSTR2DTNUMMX: 0.21 sec, DateStr2Num: 0.0087 sec

And for a {1 x 1000} cell string:

DATENUM: 2.52 sec, DTSTR2DTNUMMX: 1.77 sec, DateStr2Num: 0.027 sec

The speed is based on two methods: 1. the format has to be specified by a very limited set of 6 most common formats. 2. The value is not checked for validity: While DATENUM and DTSTR2DTNUMMX recognize ‘2011-04-180’ more or less correctly as 179th day after 2011-04-01, DateStr2Num fails and does even not catch ‘2011-04-AB’ as an error. To calculate the fractional part for ’25:61:62′, the overflow can be ignored fortunately.

Therefore, if you know that the date string is valid, a very simple C-code can be 100 times faster than DATENUM and 25 times faster than DSTR2DNUMMX.

The C-Mex DATENUMMX.c was part of Matlab 6.5. What a pitty that modern Matlab versions include less of such cookies.

Kind regards, Jan

]]>