Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Cython中测量高达毫秒的时间?_Python_C_Time_Cython - Fatal编程技术网

Python 如何在Cython中测量高达毫秒的时间?

Python 如何在Cython中测量高达毫秒的时间?,python,c,time,cython,Python,C,Time,Cython,我已经读过了,但我想得到比一秒钟更好的计时精度:这是否可能与libc的某些功能有关 这是在nogil中使用的,因此当然不允许使用Python…为什么不使用datetime?例如,datetime.datetime.now()将为您提供包括毫秒在内的当前时间值。您可以使用POSIX: 此代码段在current中存储自epoch以来的秒数,精度高达纳秒(取决于您的系统) 您也可以使用,但现在不推荐使用: POSIX.1-2008将gettimeofday()标记为过时,建议使用clock_getti

我已经读过了,但我想得到比一秒钟更好的计时精度:这是否可能与libc的某些功能有关


这是在nogil中使用的
,因此当然不允许使用Python…

为什么不使用datetime?例如,datetime.datetime.now()将为您提供包括毫秒在内的当前时间值。

您可以使用POSIX:

此代码段在
current
中存储自epoch以来的秒数,精度高达纳秒(取决于您的系统)

您也可以使用,但现在不推荐使用:

POSIX.1-2008将gettimeofday()标记为过时,建议使用clock_gettime(2)


在你的赛昂的哪一部分
.pyx
.c[pp]
?对于c:。在C++中有很多方法可以做到这一点。那么也许你可以在.pyx中做一个包装器。@XinHuang在.pyx中,我甚至没有一个.c(cython生成的除外)。这是Python,我在c中寻找一些东西(在with nogil部分…)
from posix.time cimport clock_gettime, timespec, CLOCK_REALTIME

cdef timespec ts
cdef double current
clock_gettime(CLOCK_REALTIME, &ts)
current = ts.tv_sec + (ts.tv_nsec / 1000000000.)