Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.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
Linux 过程和基准的精确性_Linux_Benchmarking_Perf_Microbenchmark_Nice - Fatal编程技术网

Linux 过程和基准的精确性

Linux 过程和基准的精确性,linux,benchmarking,perf,microbenchmark,nice,Linux,Benchmarking,Perf,Microbenchmark,Nice,过程的精确性对(微观)基准测试有影响吗?我的直觉告诉我,使用nice-20启动基准测试将产生更精确的结果,因为基准测试中发生的上下文切换更少 另一方面,许多工具或库函数不仅允许检索墙时间,还允许检索CPU时间。此外,基准机器不应该同时运行其他资源密集型进程,因此不会有太多竞争 作为一种天真的方法,我编写了一个简单的程序来测量墙时间,希望在使用不同的精确性值启动过程时看到差异: #include <stdio.h> #include <stdint.h> #include

过程的精确性对(微观)基准测试有影响吗?我的直觉告诉我,使用
nice-20
启动基准测试将产生更精确的结果,因为基准测试中发生的上下文切换更少

另一方面,许多工具或库函数不仅允许检索墙时间,还允许检索CPU时间。此外,基准机器不应该同时运行其他资源密集型进程,因此不会有太多竞争

作为一种天真的方法,我编写了一个简单的程序来测量墙时间,希望在使用不同的精确性值启动过程时看到差异:

#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>

int main() {
    struct timeval tval_before, tval_after, tval_result;
    gettimeofday(&tval_before, NULL);
    int i;
    for (i = 0; i < 2000000000; i++) {
    }
    gettimeofday(&tval_after, NULL);
    timersub(&tval_after, &tval_before, &tval_result);
    printf("Time elapsed: %ld.%06ld\n", (long int)tval_result.tv_sec, (long int)tval_result.tv_usec);
    return 0;
}
#包括
#包括
#包括
int main(){
结构时间值tval_前,tval_后,tval_结果;
gettimeofday(&tval_before,NULL);
int i;
对于(i=0;i<2000000000;i++){
}
gettimeofday(&tval_after,NULL);
timersub(&tval_后,&tval_前,&tval_结果);
printf(“经过的时间:%ld.%06ld\n”,(长int)tval_result.tv_sec,(长int)tval_result.tv_usec);
返回0;
}

但是,在测量时,使用高nice值或低nice值启动程序之间没有一致的差异。因此,我的问题是:我的基准是否没有行使受良好性影响的财产,或者良好性是否与该基准无关?准确度值在基准机器上是否相关?另外:
perf stats
上下文开关
指标是否适合测量准确度的影响

如果您只使用正常时间进行测量,那么您是对的,但是如果测量仅在CPU时间内进行,那么您将获得更精确的结果,而无需更改进程的良好值。不要使用
gettimeofday(2)
不推荐的调用,而是将
clock\u gettime(2)
与cpu时钟一起使用,您将获得进程中经过的cpu时间。如果您仅使用正常时间进行测量,则您是正确的,但是,如果测量仅在CPU时间内进行,您将获得更精确的结果,而无需更改进程的良好值。不要使用
gettimeofday(2)
不推荐的调用,而是将
clock\u gettime(2)
与cpu时钟一起使用,您将获得进程中经过的cpu时间。