I am measuring the execution time of a program written in R by writing Sys.time() at starting and end of the code and calculating the difference. The result I am getting is changing at different instances of time.
Eg: adjacent1. matrix
0 1 1 1 1 1.
1 0 1 1 1 1.
1 1 0 1 1 1.
1 1 1 0 1 1.
1 1 1 1 0 1.
1 1 1 1 1 0.
And R Code is
initial_time=Sys.time().
adjacent1%%adjacent1%%adjacent1.
final_time=Sys.time().
time=final_time-initial_time.
print(time)
When I run the code multiple times, the output is different every time.
Time difference of 0.002844095 secs.
Time difference of 0.003111839 secs.
Time difference of 0.002691031 secs.
Time difference of 0.003143072 secs.
This is a simple example. For more complicated R code, there is significant different in execution time.
Why is it so?