Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sys/time.h>
- #ifdef __MACH__
- #include <mach/clock.h>
- #include <mach/mach.h>
- #endif
- #define MAXBUF 10
- static void gettime (struct timespec *t) {
- #ifdef __MACH__
- clock_serv_t cclock;
- mach_timespec_t mts;
- host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &cclock);
- clock_get_time(cclock, &mts);
- mach_port_deallocate(mach_task_self(), cclock);
- t->tv_sec = mts.tv_sec;
- t->tv_nsec = mts.tv_nsec;
- #else
- clock_gettime(CLOCK_REALTIME, t);
- #endif
- }
- int main (void) {
- FILE *fp;
- struct timespec tic, toc;
- char *executableName = "./a.out";
- char answer[MAXBUF];
- gettime(&tic);
- if ((fp = popen(executableName, "r")) == NULL) {
- fprintf(stderr, "The file couldn't be opened.\n");
- return 1;
- }
- gettime(&toc);
- fgets(answer, MAXBUF, fp);
- double elapsed = (double)(toc.tv_nsec - tic.tv_nsec) / 1000000000;
- fprintf(stdout, "The program says %s, and took %fs to run!\n", answer, elapsed);
- pclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement