在windows中,pycurl给出了3个小数位的时间精度,有没有办法将它改进为更精确的东西?
> print c.getinfo(pycurl.CONNECT_TIME)
> 0.265
例如,Linux将它提供给大约7位小数。
答案 0 :(得分:2)
查看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,没有。遗憾!
答案 1 :(得分:2)
我担心这是底层libcurl代码的限制。它使用Windows中的GetTickCount()函数调用,即documented like this:
GetTickCount函数的分辨率仅限于 系统计时器的分辨率,通常在10的范围内 毫秒到16毫秒。