gpt4 book ai didi

fortran - 测量 Fortran 程序所花费的时间

转载 作者:行者123 更新时间:2023-12-02 22:29:59 29 4
gpt4 key购买 nike

我最近为了好玩而开始学习 Fortran,我想知道是否有任何简单的方法来显示执行我的代码所花费的时间。这只是一个数到一百万的简单循环,我想看看完成这个需要多长时间。

如果有帮助,这是我正在使用的代码:

program count
implicit none
integer :: i

do i=0,1000000
print*,i
end do
end program count

我在 Linux 上使用 gFortran 作为我的编译器。我正在使用 Geany 作为文本编辑器。

最佳答案

在 Fortran 90 或更高版本中,使用 SYSTEM_CLOCK 内部子例程:

call system_clock(beginning, rate)
result = do_computation()
call system_clock(end)
print *, "elapsed time: ", real(end - beginning) / real(rate)

关于fortran - 测量 Fortran 程序所花费的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12435169/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com