timing against c

This commit is contained in:
Danny Yoo 2011-02-09 21:09:51 -05:00
parent 350507a66f
commit 6d7fb7a275

19
experiments/fact/gauss.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <sys/time.h>
int main(int argc, char**argv) {
unsigned long i, n, acc=0;
struct timeval start, end;
sscanf(argv[1], "%lu", &n);
gettimeofday(&start, NULL);
for (i = 0; i <= n; i++) {
acc = acc + i;
}
gettimeofday(&end, NULL);
printf("%lu (%f milliseconds)\n",
acc,
(1000.0*(end.tv_sec - start.tv_sec) +
((end.tv_usec - start.tv_usec) / 1000.0) ));
}