timing against c
This commit is contained in:
parent
350507a66f
commit
6d7fb7a275
19
experiments/fact/gauss.c
Normal file
19
experiments/fact/gauss.c
Normal 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) ));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user