Skip to content

Instantly share code, notes, and snippets.

@mathyourlife
Last active October 13, 2017 10:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathyourlife/4432190 to your computer and use it in GitHub Desktop.
Save mathyourlife/4432190 to your computer and use it in GitHub Desktop.
Testing faster methods to retrieve the current system time in Matlab m-files so that simulations are not slowed down as much.
duration_1 = 0;
duration_2 = 0;
iter = 100000;
for i=1:iter
if mod(i,2) == 0
tic;
a = now();
duration_1 = duration_1 + toc;
else
tic;
a = datenummx(clock);
duration_2 = duration_2 + toc;
end
end
disp(sprintf('Standard now() function takes %0.3f seconds to run %d iterations',duration_1,iter))
disp(sprintf('datenummx(clock) takes %0.3f seconds to run %d iterations',duration_2,iter))
% Outputs
% Standard now() function takes 2.063 seconds to run 100000 iterations
% datenummx(clock) takes 0.505 seconds to run 100000 iterations ## REALLY ?! 4x faster than the standard function?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment