how to measure pipe syscall time in milliseconds?

本小妞迷上赌 提交于 2019-12-02 11:29:15

问题


I want to see the time of my pipe program system call. I need to measure it for analyzing results. How can i measure the time of system call in milliseconds?

For example, this is simple pipe program:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/timeb.h>
#include <time.h>

void main() {

    FILE *read_fp;
    char buffer[10];
    int cnt;

    memset(buffer,'\0',sizeof(buffer));
    read_fp=popen("uname -a","|");

    if (read_fp!=NULL) {
        cnt=fread(buffer,sizeof(char),9,read_fp);
        if (cnt>0) printf(buffer,"olololo");
            pclose(read_fp);
    }
}

And what is the reason of time differences, executing it more than 4 times? What's the reason of time "jumps"?

来源:https://stackoverflow.com/questions/47725553/how-to-measure-pipe-syscall-time-in-milliseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!