comparing python with c/fortran

后端 未结 8 1995
深忆病人
深忆病人 2021-02-04 10:15

I wrote the following programs to compare the speed of python with c/fortran. To get the time used by the programs I used the \"time\" command. All the programs compute the sq

8条回答
  •  一向
    一向 (楼主)
    2021-02-04 10:48

    Be aware that the calculation of r does not depend on the loop variables, so an optimizing compiler may move the calculation out of the loop, and just run the empty loop for the requested number of times; or even remove that loop completely and only do the calculation of the square root.
    A real smart optimizer may notice that you're not doing anything with the result, so the complete program may be optimized away without altering the output (i.e. nothing).

提交回复
热议问题