日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

python计时器精度_在python中获得更精确的计时器

發(fā)布時間:2023/11/27 生活经验 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python计时器精度_在python中获得更精确的计时器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用timeit很簡單。 Timer實例需要兩個字符串,第一個包含對time的操作,第二個包含在計時開始之前執(zhí)行一次的設(shè)置操作。以下代碼應該可以工作,只需將變量值更改為您想要的任何值。

import math

import time

from timeit import Timer

userInput = "0"

while not userInput.isdigit() or int(userInput) <= 0:

userInput = input("Calcular la raiz de: ") #Get input from user (userInput)

userInput = int(userInput)

epsilon = 0.000001

x=1

count=0

setup = 'from __main__ import userInput, epsilon, x, count'

operations = '''

x = 1

count = 0

while (abs(x**2 - userInput) > epsilon):

x = 0.5 * (x + (userInput/x))

count = count+1

'''

print('The operations took %.4f microseconds.' % Timer(operations, setup).timeit(1))

#run the operations again to get the x and count values

x = 1

count = 0

while (abs(x**2 - userInput) > epsilon):

x = 0.5 * (x + (userInput/x))

count = count+1

print("La raíz de", userInput, "es:",x,"implicó",count,"intentos")這將使您的代碼默認運行一百萬次,并返回運行所花費的總時間(以秒為單位)。您可以通過將數(shù)字傳遞給timeit()來運行它不同的次數(shù)。

總結(jié)

以上是生活随笔為你收集整理的python计时器精度_在python中获得更精确的计时器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。