I'm doing an exercise which require the computation of the time needed to create and destroy a thread and a process, and then compare them.
I really don’t know how to calculate the time of these operations. Anybody got an idea?
CodePudding user response:
On linux, you can use the time command:
time ./your_program
CodePudding user response:
You can use a timer:
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <sys/time.h>
int main(void)
{
struct timeval start, end, res;
gettimeofday(&start, NULL);
// Do your stuff
gettimeofday(&end, NULL);
timersub(&end, &start, &res);
printf("Time elapsed: %ld.ld\n", (long int)res.tv_sec, (long int)res.tv_usec);
return 0;
}
