【发布时间】:2012-11-04 23:55:39
【问题描述】:
在 windows 中,pycurl 将计时精度精确到小数点后 3 位,有没有办法将其提高到更精确的程度?
> print c.getinfo(pycurl.CONNECT_TIME)
> 0.265
例如,Linux 将其保留到小数点后 7 位。
【问题讨论】:
标签: python windows curl libcurl
在 windows 中,pycurl 将计时精度精确到小数点后 3 位,有没有办法将其提高到更精确的程度?
> print c.getinfo(pycurl.CONNECT_TIME)
> 0.265
例如,Linux 将其保留到小数点后 7 位。
【问题讨论】:
标签: python windows curl libcurl
查看pycurl的源码,它只是调用了底层的cURL函数:
case CURLINFO_CONNECT_TIME: // other cases [snip]ped
/* Return PyFloat as result */
double d_res = 0.0;
res = curl_easy_getinfo(self->handle, (CURLINFO)option, &d_res);
if (res != CURLE_OK) {
CURLERROR_RETVAL();
}
return PyFloat_FromDouble(d_res);
}
反过来
case CURLINFO_CONNECT_TIME:
*param_doublep = data->progress.t_connect;
break;
而t_connect 是由分配的
data->progress.t_connect = Curl_tvdiff_secs(now, data->progress.t_startsingle);
其中引用t_startsingle,由Curl_tvnow分配,在Windows下定义为
struct timeval curlx_tvnow(void)
{
/*
** GetTickCount() is available on _all_ Windows versions from W95 up
** to nowadays. Returns milliseconds elapsed since last system boot,
** increases monotonically and wraps once 49.7 days have elapsed.
*/
struct timeval now;
DWORD milliseconds = GetTickCount();
now.tv_sec = milliseconds / 1000;
now.tv_usec = (milliseconds % 1000) * 1000;
return now;
}
即毫秒精度。
没有修补和重新编译 cURL 以使用更高精度的计时器,然后针对它编译 pyCURL,不。对不起!
【讨论】:
恐怕这是底层 libcurl 代码的限制。它使用Windows中的GetTickCount()函数调用,即documented like this:
GetTickCount 函数的分辨率仅限于 系统定时器的分辨率,通常在 10 范围内 毫秒到 16 毫秒。
【讨论】: