鱼C论坛

 找回密码
 立即注册
查看: 3558|回复: 1

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

[复制链接]
发表于 2022-10-22 21:25:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import threading  # 线程模块
  2. import time


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


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


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


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

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

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

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


  21. # eat_breakfast()
  22. # drink_coffee()
  23. # study()


  24. print(threading.active_count())  # 函数名活动计数
  25. print(threading.enumerate())  # 函数名枚举
  26. 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
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-10-23 02:52:30 | 显示全部楼层
视频教程输出只有5.1390643s,我的输出是9517.6617491s,这没道理呀
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 03:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表