| 1 |
# cpu_time(x): CPU Elapsed Time |
| 2 |
|
| 3 |
CPU elapsed time in seconds. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = cpu_time(x) |
| 11 |
pure subroutine cpu_time(x) |
| 12 |
``` |
| 13 |
|
| 14 |
### Arguments |
| 15 |
|
| 16 |
`x` the input value should be of type real with `intent(out)`. |
| 17 |
|
| 18 |
### Return values |
| 19 |
|
| 20 |
None. |
| 21 |
|
| 22 |
## Description |
| 23 |
|
| 24 |
**cpu_time(time)** returns a real value representing the elapsed CPU time in |
| 25 |
seconds. If tine source is available, time will be reported with microsecond |
| 26 |
resolution. If no time source is available, TIME is set to -1.0. |
| 27 |
|
| 28 |
This is useful for testing segments of code to determine computation time. |
| 29 |
|
| 30 |
For `cpu_time(time)` the absolute value is meaningless, only differences between |
| 31 |
subsequent calls to this subroutine, as shown in the example below, should be used. |
| 32 |
|
| 33 |
## Types |
| 34 |
|
| 35 |
Supported input parameter types is real with `intent(out)`. |
| 36 |
|
| 37 |
```fortran |
| 38 |
pure subroutine cpu_time(t) |
| 39 |
real(dp), intent(out) :: t |
| 40 |
call c_cpu_time(t) |
| 41 |
end subroutine |
| 42 |
``` |
| 43 |
|
| 44 |
## Examples |
| 45 |
|
| 46 |
```fortran |
| 47 |
program intrinsics_cpu_time |
| 48 |
implicit none |
| 49 |
real(dp) :: t1, t2 |
| 50 |
call cpu_time(t1) |
| 51 |
print *, "Some computation" |
| 52 |
call cpu_time(t2) |
| 53 |
print *, "Total time: ", t2-t1 |
| 54 |
end program |
| 55 |
``` |
| 56 |
|
| 57 |
**Result:** |
| 58 |
|
| 59 |
``` |
| 60 |
Some computation |
| 61 |
20 |
| 62 |
``` |
| 63 |
|
| 64 |
## See Also |