silly tests added by Kooda on Sat Aug 15 20:40:26 2015
(define a '((vx . 123) (vy . 84) (vz . -39) (z . 281) (y . 384) (x . 38))) (define undefined '(undefined)) (define (undefined? o) (eqv? o undefined)) (define (myassoc searched-key alist) (if (null? alist) undefined (let* ((binding (car alist))) (if (eqv? (car binding) searched-key) (cdr binding) (myassoc searched-key (cdr alist)))))) (define (test-vals) (let loop ((alist a) (x undefined) (y undefined) (z undefined)) (if (or (null? alist) (not (or (undefined? x) (undefined? y) (undefined? z)))) (void x y z) (let* ((binding (car alist)) (rest (cdr alist)) (key (car binding)) (value (cdr binding))) (cond ((and (eqv? key 'x) (undefined? x)) (loop rest value y z)) ((and (eqv? key 'y) (undefined? y)) (loop rest x value z)) ((and (eqv? key 'z) (undefined? z)) (loop rest x y value)) (else (loop rest x y z))))))) (define (test-naive) (let ((x (myassoc 'x a)) (y (myassoc 'y a)) (z (myassoc 'z a))) (void x y z))) (define (bench times) (print "bench test-naive") (time (let loop ((i 0)) (test-naive) (unless (= i times) (loop (add1 i))))) (print "bench test-vals") (time (let loop ((i 0)) (test-vals) (unless (= i times) (loop (add1 i)))))) (cond-expand ((or compiling script) (bench 10000000)) (else (void))) Results: [kooda@black-star /tmp] % csc test.scm [kooda@black-star /tmp] % ./test bench test-naive 16.111s CPU time, 0.265s GC time (major), 176/43408 GCs (major/minor) bench test-vals 21.364s CPU time, 1.754s GC time (major), 1206/134823 GCs (major/minor) [kooda@black-star /tmp] % csc -O5 test.scm [kooda@black-star /tmp] % ./test bench test-naive 2.867s CPU time, 0/1221 GCs (major/minor) bench test-vals 8.559s CPU time, 0.811s GC time (major), 557/88112 GCs (major/minor)