comparing python with c/fortran

后端 未结 8 1991
深忆病人
深忆病人 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 10:41

    Flawed benchmark.

    If you want to time floating point arithmetic, then you should first time the loops doing nothing (or as close to nothing as you can manage). To avoid optimizing away the whole loop, make sure it is doing something like moving a single byte char from one array to another.

    Then time it again with the floating point calculation and subtract the first timing to get a more accurate number.

    Also, Python only has double floating point numbers so a more even test would ensure that the other languages also use floating point. And as others have mentioned, Python is widely used for scientific computing but those scientists generally use the numpy library to do matrix calculations rather than writing Python loops.

提交回复
热议问题