我想看看管道处理数据需要多长时间,我存储了
的结果clock_gettime (CLOCK_REALTIME, &start);
当我将数据项添加到输入缓冲区时。
然后,当我计算处理该项目所需的时间时,我会使用该时间。
对于前几个项似乎没问题,但之后我得到了疯狂的结果。
我计算出使用此功能所用的时间
double xelapsed (struct timespec a, struct timespec b)
{
return (a.tv_sec - b.tv_sec) * 1000000.0
+ (a.tv_nsec - b.tv_nsec) / 1000.0;
}
这就是我最终的结果:
bash-4.1$ ./pipe
Latency: 1.447000 μs
Latency: 81.549000 μs
Latency: 104.253000 μs
Latency: 112.497000 μs
Latency: 121.307000 μs
Latency: 128.993000 μs
Latency: 136.334000 μs
Latency: 143.237000 μs
Latency: 147.910000 μs
Latency: 152.242000 μs
Latency: 156.492000 μs
Latency: 160.729000 μs
Latency: 164.793000 μs
Latency: 168.782000 μs
Latency: 172.756000 μs
Latency: 176.720000 μs
Latency: 175.370000 μs
Latency: 184.937000 μs
Latency: 183.424000 μs
Latency: 187.353000 μs
Latency: 196.870000 μs
Latency: 200.874000 μs
Latency: 205.332000 μs
Latency: 209.353000 μs
Latency: 213.677000 μs
Latency: 218.040000 μs
Latency: 222.435000 μs
Latency: 226.559000 μs
Latency: 230.897000 μs
Latency: 235.170000 μs
Latency: 239.481000 μs
Latency: 243.829000 μs
Latency: 247.709000 μs
Latency: 251.974000 μs
Latency: 256.338000 μs
Latency: 260.363000 μs
Latency: 264.832000 μs
Latency: 269.293000 μs
Latency: 273.171000 μs
Latency: 277.525000 μs
Latency: 281.701000 μs
Latency: 285.674000 μs
Latency: 290.187000 μs
Latency: 294.239000 μs
Latency: 298.504000 μs
Latency: 302.604000 μs
Latency: 307.095000 μs
Latency: 310.792000 μs
Latency: 315.343000 μs
Latency: 318.812000 μs
Latency: 322.721000 μs
Latency: 327.149000 μs
Latency: 331.065000 μs
Latency: 335.114000 μs
Latency: 339.632000 μs
Latency: 342.989000 μs
Latency: 344.433000 μs
Latency: 348.567000 μs
Latency: 352.376000 μs
Latency: 356.801000 μs
Latency: 360.752000 μs
Latency: 364.337000 μs
Latency: 368.808000 μs
Latency: 372.082000 μs
Latency: 376.500000 μs
Latency: 380.283000 μs
Latency: 384.611000 μs
Latency: 388.134000 μs
Latency: 392.083000 μs
Latency: 396.484000 μs
Latency: 400.428000 μs
Latency: 1426625359409111.000000 μs
Latency: 1426625359409117.250000 μs
Latency: 1426625359409123.250000 μs
Latency: 1426625359409128.750000 μs
Latency: 1426625359409134.500000 μs
Latency: 1426625359409140.500000 μs
Latency: 1426625359409146.000000 μs
Latency: 1426625359409151.750000 μs
Latency: 1426625359409157.500000 μs
Latency: 1426625359409163.000000 μs
Latency: 1426625359409168.500000 μs
Latency: 1426625359409174.250000 μs
Latency: 1426625359409180.000000 μs
Latency: 1426625359409185.500000 μs
Latency: 1426625359409191.000000 μs
Latency: 1426625359409196.750000 μs
Latency: 1426625359409202.250000 μs