Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 jaar geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module CTimer
  2. use ifwin, only: QueryPerformanceFrequency, QueryPerformanceCounter, T_LARGE_INTEGER
  3. use ISO_C_BINDING
  4. use ISO_FORTRAN_ENV
  5. implicit none
  6. public
  7. type, public :: Timer
  8. type(T_LARGE_INTEGER) :: StartTime
  9. type(T_LARGE_INTEGER) :: EndTime
  10. contains
  11. procedure :: Start => Start
  12. procedure :: Finish => Finish
  13. procedure :: ElapsedTimeMs => ElapsedTime
  14. end type Timer
  15. contains
  16. subroutine Start(this)
  17. implicit none
  18. class(Timer), intent(inout) :: this
  19. integer :: ApiResult
  20. ApiResult = QueryPerformanceCounter(this%StartTime)
  21. end subroutine
  22. subroutine Finish(this)
  23. implicit none
  24. class(Timer), intent(inout) :: this
  25. integer :: ApiResult
  26. ApiResult = QueryPerformanceCounter(this%EndTime)
  27. end subroutine
  28. integer function ElapsedTime(this)
  29. implicit none
  30. class(Timer), intent(inout) :: this
  31. real(kind=REAL128) :: time
  32. time = CalcTime(this%StartTime, this%EndTime)
  33. ElapsedTime = int(time * 1000.0)
  34. end function
  35. real(kind=REAL128) function CalcTime(start, finish)
  36. implicit none
  37. type(T_LARGE_INTEGER), intent(in) :: start
  38. type(T_LARGE_INTEGER), intent(in) :: finish
  39. type(T_LARGE_INTEGER) :: freq
  40. integer :: ApiResult
  41. integer(kind=INT64) :: freq_64
  42. integer(kind=INT64) :: start_64
  43. integer(kind=INT64) :: finish_64
  44. start_64 = Make64(start)
  45. finish_64 = Make64(finish)
  46. ApiResult = QueryPerformanceFrequency(freq)
  47. freq_64 = Make64( freq)
  48. CalcTime = real(finish_64-start_64,kind=REAL128) / real(freq_64,kind=REAL128)
  49. end function
  50. integer(kind=INT64) function Make64(bit64_int)
  51. type(T_LARGE_INTEGER), intent(in) :: bit64_int
  52. Make64 = transfer(bit64_int, 0_INT64)
  53. end function
  54. end module CTimer