Created
April 23, 2021 08:26
-
-
Save alsamitech/fd766d263afebbf58b57fabb80d44a00 to your computer and use it in GitHub Desktop.
Like time, but more accurate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <time.h> | |
| #ifndef __unix__ | |
| #error only supports unix! | |
| #endif // __unix__ | |
| #include <unistd.h> | |
| double ExecuteAC(char** argv){ | |
| pid_t pid=fork(); | |
| if(pid==0){ | |
| // child process | |
| execv(argv[0], argv); | |
| exit(127); | |
| }else{ | |
| // parent process | |
| long before=clock(); | |
| waitpid(pid, 0, 0); | |
| long after=clock(); | |
| return (double) (after-before)/CLOCKS_PER_SEC; | |
| } | |
| } | |
| int main(int argc, char** argv){ | |
| if(argc<2){ | |
| printf("Usage: %s <filenm>", argv[0]); | |
| return 0; | |
| } | |
| printf("Time: %lf", ExecuteAC(argv+1)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment