Last active
October 13, 2017 10:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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