Skip to content

Instantly share code, notes, and snippets.

@llibra
Created June 18, 2011 13:13
Show Gist options
  • Save llibra/1033083 to your computer and use it in GitHub Desktop.
Save llibra/1033083 to your computer and use it in GitHub Desktop.
Performance of m-v-l
(defun mvb (f)
(declare (optimize (speed 3) (safety 1) (debug 1)))
(multiple-value-bind (x y) (funcall f)
(values (+ x y) (- x y))))
(defun mvl (f)
(declare (optimize (speed 3) (safety 1) (debug 1)))
(let* ((l (multiple-value-list (funcall f)))
(x (car l))
(y (cadr l)))
(declare (dynamic-extent l)
(type list l))
(values (+ x y) (- x y))))
(flet ((f ()
(values (random 100) (random 100))))
(time (iter (repeat 10000000)
(sum (multiple-value-bind (x y) (mvb #'f)
(+ x y)))))
(time (iter (repeat 10000000)
(sum (multiple-value-bind (x y) (mvl #'f)
(+ x y))))))
; (ITER (REPEAT 10000000) (SUM (MULTIPLE-VALUE-BIND (X Y) (MVB #'F) (+ X Y)))) took 1,570,168 microseconds (1.570168 seconds) to run
; with 2 available CPU cores.
; During that period, 1,508,985 microseconds (1.508985 seconds) were spent in user mode
; 1,360 microseconds (0.001360 seconds) were spent in system mode
; (ITER (REPEAT 10000000) (SUM (MULTIPLE-VALUE-BIND (X Y) (MVL #'F) (+ X Y)))) took 1,663,267 microseconds (1.663267 seconds) to run
; with 2 available CPU cores.
; During that period, 1,605,071 microseconds (1.605071 seconds) were spent in user mode
; 2,342 microseconds (0.002342 seconds) were spent in system mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment