;;; srfi-4 chicken benchmarking test ;;; /.chickens/be678994/bin/csc -k -m main -O5 srfi-4-stress-test.scm ;;; ;;; $ convert wizard: -resize 2000x-1 png:- | ./srfi-4-stress-test /tmp/wizard.png (import stb-image stb-image-write (only (chicken process-context) command-line-arguments) (only (chicken time) time) srfi-4) (define fn-out (car (command-line-arguments))) (define (image-half pixels w h c) (define (half n) (quotient n 2)) (define hw (- (half w) 1)) (define hh (- (half h) 1)) (define (average a b c d) (quotient (+ a b c d) 4)) (define (ref p x y z) (u8vector-ref p (+ z (* c (+ x (* w y)))))) (let ((out (make-u8vector (* w h c)))) (do ((y 0 (+ y 1))) ((>= y hh)) (do ((x 0 (+ x 1))) ((>= x hw)) (do ((z 1 (+ z 1))) ((> z c)) (u8vector-set! out (+ z (* c (+ x (* hw y)))) (average (ref pixels (+ (* x 2) 0) (+ (* y 2) 0) z) (ref pixels (+ (* x 2) 0) (+ (* y 2) 1) z) (ref pixels (+ (* x 2) 1) (+ (* y 2) 0) z) (ref pixels (+ (* x 2) 1) (+ (* y 2) 1) z) ))))) (values out hw hh c))) (receive (pixels w h c) (read-image) (with-output-to-file fn-out (lambda () (receive (pixels w h c) (time (image-half pixels w h c)) (write-png pixels w h c)))))