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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python实训计算总秒数,Python:如何获取每个吉利秒数

發布時間:2025/3/20 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python实训计算总秒数,Python:如何获取每个吉利秒数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I'd like to know the HZ of the system, i.e. how many mili seconds is one jiffy from Python code.

解決方案

There is USER_HZ

>>> import os

>>> os.sysconf_names['SC_CLK_TCK']

2

>>> os.sysconf(2)

100

which is what the kernel uses to report time in /proc.

From the time(7) manual page:

The Software Clock, HZ, and Jiffies

The accuracy of various system calls that set timeouts, (e.g.,

select(2), sigtimedwait(2)) and measure CPU time (e.g., getrusage(2))

is limited by the resolution of the software clock, a clock maintained

by the kernel which measures time in jiffies. The size of a jiffy is

determined by the value of the kernel constant HZ.

The value of HZ varies across kernel versions and hardware platforms.

On i386 the situation is as follows: on kernels up to and including

2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with

2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since

kernel 2.6.13, the HZ value is a kernel configuration parameter and can

be 100, 250 (the default) or 1000, yielding a jiffies value of, respec‐

tively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further

frequency is available: 300, a number that divides evenly for the com‐

mon video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

The times(2) system call is a special case. It reports times with a

granularity defined by the kernel constant USER_HZ. Userspace applica‐

tions can determine the value of this constant using

sysconf(_SC_CLK_TCK).

If you absolutely must know SYSTEM_HZ:

>>> from ctypes import *

>>> rt = CDLL('librt.so')

>>> CLOCK_REALTIME = 0

>>> class timespec(Structure):

... _fields_ = [("tv_sec", c_long), ("tv_nsec", c_long)]

...

>>> res = timespec()

>>> rt.clock_getres(CLOCK_REALTIME, byref(res))

0

>>> res.tv_sec, res.tv_nsec

(0, 4000250)

>>> SYSTEM_HZ = round(1/(res.tv_sec + (res.tv_nsec/10.0**9)))

Gives 250 on my laptop (which sounds about right) and 1000000000 in a VM…

總結

以上是生活随笔為你收集整理的python实训计算总秒数,Python:如何获取每个吉利秒数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。