changeset 23249:21fc54e4bb7b

dir.m: Improve performance by another 2X (bug #50416). * dir.m: Replace call to datenum within for loop to a single call outside of for loop.
author Rik <rik@octave.org>
date Mon, 06 Mar 2017 11:19:31 -0800
parents 529c6d0c6684
children b7da08507fae
files scripts/miscellaneous/dir.m
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/dir.m	Mon Mar 06 09:31:32 2017 -0800
+++ b/scripts/miscellaneous/dir.m	Mon Mar 06 11:19:31 2017 -0800
@@ -135,11 +135,17 @@
         info(i,1).date = strftime ("%d-%b-%Y %T", lt);
         info(i,1).bytes = st.size;
         info(i,1).isdir = S_ISDIR (st.mode);
-        info(i,1).datenum = datenum (lt.year + 1900, lt.mon + 1, lt.mday,
-                                     lt.hour, lt.min, lt.sec);
+        info(i,1).datenum = [lt.year + 1900, lt.mon + 1, lt.mday, ...
+                             lt.hour, lt.min, lt.sec];
         info(i,1).statinfo = st;
       endif
     endfor
+    ## A lot of gymnastics in order to call datenum just once.  2x speed up.
+    dvec = [info.datenum]([[1:6:end]', [2:6:end]', [3:6:end]', ...
+                           [4:6:end]', [5:6:end]', [6:6:end]']);
+    dnum = datenum (dvec);
+    ctmp = mat2cell (dnum, ones (nf,1), 1);
+    [info.datenum] = ctmp{:};
   endif
 
   ## Return the output arguments.