This is an intrinsic subroutine that uses the systems internal clock.
This subroutine will use the system's internal clock to measure total elapsed time. When using differences between results of this subroutine to time portions of your code, please remember that the computer will measure the total time it takes for the operations to be completed, not the actual time the computer spent executing your task. For instance, during peak system use, many users will be issuing commands to the system. To get all these done, the system may temporarily shove your process in the background while it takes care of other people's requests. This can dramatically increase the time the system takes to complete your process. Therefore, to get more accurate times of execution, try to run this subroutine during times of low system usage. Also, be aware that the clock is periodically reset to zero (usually and midnight). Timings that span this reset will get strange results unless you program special corrective action based on the maximum count of the clock.
system_clock (count, count_rate, count_max)
You should provide an integer variable to the subroutine as the count argument. On return, the variable will contain a value that corresponds to the current number of clock ticks the system has done since it last reset itself. For instance, if the system's clock registers 100 ticks per second, and you issued a call to system_clock precisely at noon, the value stored in the count argument would be 4,320,000 ( assuming the system resets itself everyday at midnight ).
Again you should provide an integer variable to the computer for this argument. The value that is returned in this variable, is the number of ticks the system's internal clock counts every second. For example, in the scenario defined in the explanation of the count argument, count_rate would equal 100.
Count_max is the number of ticks that the clock will count before it resets itself to zero. So, for an internal clock that counts 100 ticks per second and that resets itself every twenty four hours, the value of count_max would be 8,640,000.
Please keep in mind that in the following example the actual numerical results of the call to system_clock can be highly variable. The speed of internal processor on the system you are using, the number of users on your system and whether or not you are running from a remote terminal or not can all produce a high degree of variance in the run times that system clock will report. The only way to get decent results from any timing procedure you do is to run it several times. This way you can look over your results and find the smallest amount of time the computer required for your task. This smallest value should be relatively close to the actual time the computer spent specifically running your task.
At various times you may be interested in how much time the computer spends executing different parts of some program. To find out, issue calls to system_clock before and after each segment of the program you are interesting. Afterwards you can print out the number of seconds that were spent completing that block of code. For example, look at the following:
call system_clock(icount1,irate,imax) do I=1,1000000 X(i)=sqrt(i+1) end do call system_clock(icount2,irate,imax) time = (icount2-icount1)/irate print *,'Execution time in seconds is:', time
The first call to system_clock will return the number of clock ticks ( icount1) before execution of the do loop. After the lengthy do loop is complete, the second call to system_clock will return the number of clock ticks immediately after the loop has finished (icount2). Now, to get the time spent in execution of the loop, subtract icount1 is from icount2 and divide by the number of ticks per second (irate). Finally, the print statement sends the elapsed time to the monitor.
Written by Jason Wehr : email@example.com and Maintained by John Mahaffy : firstname.lastname@example.org