Boibot 发表于 2022-10-22 21:25:51

time.perf_counter()返回性能计数器的值(以秒的小数部分为单位),我的输出不符标准

import threading# 线程模块
import time


def eat_breakfast():
    time.sleep(3)
    print("You eat breakfast")


def drink_coffee():
    time.sleep(4)
    print("You drank coffee")


def study():
    time.sleep(5)
    print("You finish studying")


x = threading.Thread(target=eat_breakfast, args=())
x.start()

y = threading.Thread(target=drink_coffee, args=())
y.start()

z = threading.Thread(target=study, args=())
z.start()

x.join()   # thread synchronization(线程同步)
y.join()   # thread synchronize and join(线程同步并加入)
z.join()


# eat_breakfast()
# drink_coffee()
# study()


print(threading.active_count())# 函数名活动计数
print(threading.enumerate())# 函数名枚举
print(time.perf_counter())# performance counter function(函数名性能计数器)

console window:
You eat breakfast
You drank coffee
You finish studying
1
[<_MainThread(MainThread, started 14744)>]
9517.6617491

Boibot 发表于 2022-10-23 02:52:30

视频教程输出只有5.1390643s,我的输出是9517.6617491s,这没道理呀{:10_245:}
页: [1]
查看完整版本: time.perf_counter()返回性能计数器的值(以秒的小数部分为单位),我的输出不符标准