测量从开始执行python程序到结束执行的时间间隔

问题描述 投票:0回答:1

我一直在尝试将代码添加到下面的脚本中,以测量屏幕保持打开和关闭的时间。我在运行pygame时遇到问题,因此我想找到一种无需使用pygame即可计算此时间间隔的方法。我在stack.overflow中查看了几个问题,但没有一个真正能说明我的python屏幕程序保持打开状态的时间。还有一些答案是pygame,而我会避免pygame收到错误消息。

import turtle

#Set up the screen
wn = turtle.Screen()
wn.bgcolor("black")
wn.title("Test")
wn.bgpic("grid.png")
python performance timer clock execution
1个回答
0
投票

您尝试过这个好先生吗?

import turtle 
import time
start_time = time.time()
#Set up the screen 
try:
    wn = turtle.Screen() 
    wn.bgcolor("black") 
    wn.title("Test") 
    wn.bgpic("grid.png")
    print("Execution time :  %s seconds " % (time.time() - start_time))
except Exception as e:
    print("Program exited by error",e)
    print("Execution time : %s seconds " % (time.time() - start_time))

© www.soinside.com 2019 - 2024. All rights reserved.