这是一个很无聊但是很有意义的测试
对开发或者比较语言速度都有用
测试1秒钟内该语言在该主机上能加多少次:
以Python为例:
——————————————————————————
"""
To test how fast the computer runs python
"""
import time
print("This is to test how many times your computer can add
in 1 second by a timer loop")
a = 0
start_time = time.time()
while time.time() -start_time <1:
a += 1
print( "Total of additions: ", a)
b = 0
start_time = time.time()
for i in range(a):
b +=1
time_used = time.time()-start_time
print( "Real additions only take %.3f sec." %(time_used))
while True: pass
——————————————————————————
H**r 发帖数: 10015
2
跑不同的程序,不同的语言速度会差很多。
【在 m*****n 的大作中提到】 : 这是一个很无聊但是很有意义的测试 : 对开发或者比较语言速度都有用 : 测试1秒钟内该语言在该主机上能加多少次: : 以Python为例: : —————————————————————————— : """ : To test how fast the computer runs python : """ : import time : print("This is to test how many times your computer can add