Skip to content

Instantly share code, notes, and snippets.

@wobbol
Last active December 12, 2017 05:53
Show Gist options
  • Save wobbol/5205da12569577948af005a40cde8ce7 to your computer and use it in GitHub Desktop.
Save wobbol/5205da12569577948af005a40cde8ce7 to your computer and use it in GitHub Desktop.
benchmark gcc and clang
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/times.h>
double run(char *arg[])
{
pid_t pid = fork();
if(pid == 0) {
execvp(arg[0], arg);
}
wait(NULL);
struct tms t;
times(&t);
return (double)(t.tms_cutime + t.tms_cstime)/sysconf(_SC_CLK_TCK);
}
int main(int argc, char *argv[])
{
if(argc != 2) {
fprintf(stderr, "usage: %s filename", argv[0]);
return 1;
}
char *gcc[] = {"gcc", argv[1], "-o", "./test.gcc", (char*)NULL};
char *clang[] = {"clang", argv[1],"-o", "./test.clang", (char*)NULL};
printf(
"prog sec\n"
"---------\n"
"gcc %lf\n"
"clang %lf \n", run(gcc), run(clang));
//remove("./test.gcc");
//remove("./test.clang");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment