measuring rough scale of performance difference
This commit is contained in:
parent
6d7fb7a275
commit
4c4b9219c8
|
@ -2,9 +2,9 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
int main(int argc, char**argv) {
|
int main(int argc, char**argv) {
|
||||||
unsigned long i, n, acc=0;
|
unsigned long long i, n, acc=0;
|
||||||
struct timeval start, end;
|
struct timeval start, end;
|
||||||
sscanf(argv[1], "%lu", &n);
|
sscanf(argv[1], "%llu", &n);
|
||||||
|
|
||||||
|
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
|
@ -12,7 +12,7 @@ int main(int argc, char**argv) {
|
||||||
acc = acc + i;
|
acc = acc + i;
|
||||||
}
|
}
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
printf("%lu (%f milliseconds)\n",
|
printf("%llu (%f milliseconds)\n",
|
||||||
acc,
|
acc,
|
||||||
(1000.0*(end.tv_sec - start.tv_sec) +
|
(1000.0*(end.tv_sec - start.tv_sec) +
|
||||||
((end.tv_usec - start.tv_usec) / 1000.0) ));
|
((end.tv_usec - start.tv_usec) / 1000.0) ));
|
||||||
|
|
18
experiments/fact/gauss.rkt
Normal file
18
experiments/fact/gauss.rkt
Normal 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))
|
Loading…
Reference in New Issue
Block a user