Python
import time
start=time.time()
j=0
for h in range(20000):
for i in range(10000):
j=j+i
print(j,(time.time()-start))
Python 3.8.6 VSCode中Debug 模式
Python 3.8.6
Pypy 3.7.10
C
#include "time.h"
#include "stdio.h"
int main(int argc, char const *argv[])
{
int i;
int h;
double j=0;
clock_t start=clock();
for(h=0;h<20000;h++)
for(i=0;i<10000;i++)
{
j=j+i;
}
printf("%f %f seconds",j,((double)(clock()-start)/CLOCKS_PER_SEC));
return 0;
}
数据:
语言 | 结果 | 耗时 | 效率倍数 | 备注 |
Python3.8 Debug | 999900000000 | 28.746 | 1 | |
Python3.8 | 999900000000 | 16.506 | 1.742 | |
Pypy 3.7.10 | 999900000000 | 0.202 | 142.3 | 是不是哪里出错了? |
C | 999900000000.000000 | 0.425 | 67.638 |
Tips:这里只是简单的循环对比,实际业务上各种操作得出得效率倍数应该不会是这样的,这里只是对比个大概印象