Is the performance of comparing datetime datatypes slower than datenum

8 vues (au cours des 30 derniers jours)
Tom
Tom le 15 Juil 2016
Réponse apportée : Tom le 16 Juil 2016
I'm finding where a desired timestamp (`datetime`) fits within a large datetime array. However, this step takes a very long time and from the profiler, it appears most of the time is spent on datevec. Would it be faster to convert everything over to datenum values?
Currently the comparison step looks like this:
tol = duration(0,0,0,40);
time = datetime(timeIn);
idx = arrayfun(@(x) find(abs(x.time-time)<=tol),obj,'uni',0);
  1 commentaire
dpb
dpb le 15 Juil 2016
What's the form of timeIn? What may help is to give the specific format; at one time (I believe/maybe still does?) datenum looked at each element if a format wasn't provided which was much slower than with the appropriate format.
I'd not be terribly surprised if as a rule datetime is somewhat slower than datenum simply because it's more capable as well as the object stuff will add some overhead as well, in all likelihood.
I can't test the comparative here, though...

Connectez-vous pour commenter.

Réponse acceptée

Tom
Tom le 16 Juil 2016
Based on testing, it is much faster to compare dates using datenum instead of datetime, even after converting to datenum from datetime. I'm supposing dpb was correct about the overhead involved in the datetime datatype, but I'm only speculating. It is nice to know that converting within a calculation improves performance, because the datetime type is very convenient in all other aspects.
tic; arrayfun(@(x) find(abs(datenum(x.dateTime)-datenum(timeDate))<=tol),obj(1),'uni',0); toc;
Elapsed time is 0.021072 seconds.
tic; arrayfun(@(x) find(abs(datenum(x.dateTime)-datenum(timeDate))<=datenum(tol)),obj(1),'uni',0); toc;
Elapsed time is 0.007963 seconds.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by