Skip to content

Instantly share code, notes, and snippets.

@furushchev
Last active July 14, 2016 14:33
Show Gist options
  • Save furushchev/3832ffbb13503f5f7372b39e42a07e2f to your computer and use it in GitHub Desktop.
Save furushchev/3832ffbb13503f5f7372b39e42a07e2f to your computer and use it in GitHub Desktop.
;; bench-transpose-image.l
;; Author: Yuki Furuta <furushchev@jsk.imi.i.u-tokyo.ac.jp>
(compiler::compile-file-if-src-newer "transpose_image")
(load "transpose_image")
(setq *img* (instance image::color-image24 :init 640 480 (make-string (* 3 640 480))))
(setq *cnt* 10)
(when (compiled-function-p #'transpose-in-eus)
(warning-message 3 "~%~%===== ~A transpose in eus (compiled) ======~%" *cnt*)
(bench (dotimes (i *cnt*) (transpose-in-eus *img*))))
(load "transpose_image.l")
(unless (compiled-function-p #'transpose-in-eus)
(warning-message 3 "~%~%===== ~A transpose in eus (not compiled) ======~%" *cnt*)
(bench (dotimes (i *cnt*) (transpose-in-eus *img*))))
(warning-message 3 "~%===== ~A transpose in C ======~%" *cnt*)
(bench (dotimes (i *cnt*) (gl::transpose-image-rows *img*)))
  • Macbook Pro Retina 10,1
===== 10 transpose in eus (compiled) ======
;; time -> 1.73079[s]

===== 10 transpose in eus (not compiled) ======
;; time -> 25.5784[s]

===== 10 transpose in C ======
;; time -> 0.000631[s]
Code Time (s) Comparison
Lisp 25.5784 1
Lisp (Compiled) 1.73079 2742
C (defforeign) 0.000631 40536
;; transpose_image.l
;; Author: Yuki Furuta <furushchev@jsk.imi.i.u-tokyo.ac.jp>
(defun transpose-in-eus (img)
(let ((width (send img :width))
(height (send img :height))
(imgbuf (send img :entity)))
(let ((b (make-string (* width height 3))))
(dotimes (x width)
(dotimes (y height)
(dotimes (z 3)
(setf (elt b (+ (* (- height y 1) width 3) (* x 3) z))
(elt imgbuf (+ (* y width 3) (* x 3) z))))))
(instance image::color-image24 :init width height b))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment