I have this function, the input is the var “cmd” for example a dmesg command.
int i = 0;
char * bufferf;
bufferf = ( char * ) calloc( sizeof ( char ) , 200000 );
char buffer[1000][1280];
memset(buffer,0,1000 * 1280);
memset(bufferf,0,strlen(bufferf));
FILE* pipe = popen(cmd, "r");
if (!pipe){
send(client_fd,"EXCEPTION",9,0);
}
while(!feof(pipe)) {
if(fgets(buffer[i], 128, pipe) != NULL)
{
strcat(bufferf, buffer [i] );
}
i++;
}
pclose(pipe);
std::cout << bufferf ;
send(client_fd,bufferf,strlen(bufferf),0); }
Well. My goal is to calculate the amount of time between the start and the end of the while statement, by adding for each time a var that count the time passed.
For example dmesg is ~700 lines of output. The while runs for 700 times I have to add 700 times the amount of time to calculate the total sum.
How can I do that?
I’ve tried with difftime but it doesn’t work very well.
Any other solutions?
Thank you.
You could make an extremely basic class that uses clock() to measure the time:
Obviously multiply by 1000 if you want to display the time in milliseconds.
And then just:
Also, take note of what sarnold said,
bufferis huge.