measuring rough scale of performance difference

This commit is contained in:
Danny Yoo 2011-02-09 21:22:07 -05:00
parent 6d7fb7a275
commit 4c4b9219c8
2 changed files with 21 additions and 3 deletions

View File

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

View File

@ -0,0 +1,18 @@
#lang racket/base
(define (gauss n)
(gauss-iter n 0))
(define (gauss-iter n acc)
(if (= n 0)
acc
(gauss-iter (sub1 n) (+ acc n))))
(define n (string->number (vector-ref (current-command-line-arguments) 0)))
(define start (current-inexact-milliseconds))
(define result (gauss n))
(define end (current-inexact-milliseconds))
(printf "~a (~a milliseconds)\n" result (- end start))