Hi,

Attached is a benchmarking test that resizes a u8vector of RGB pixels into
half the size in each dimension using a pixel average.

I applied Peter's patch which inlines vector-ref and vector-set! procedures:
http://lists.nongnu.org/archive/html/chicken-hackers/2019-04/msg00041.html

With this patch, I see about a 2x speedup which is nice. I see vector_ref
and vector_set in the generated C code. However, the C code still has a
continuation call inside the main loop. Maybe someone can look into why
this is happening.

K.
PS. `convert` comes from imagemagick on most distros
;;; 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)))))
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to