Here's what I ran:
- Code: Select all
(defparameter *cycle* 0)
(defun test-arg (num cycle)
(rem cycle (1+ num)))
(defun test-dyn (num)
(rem *cycle* (1+ num)))
(defun measure ()
(time
(let ((cycle 0)
(acc 0))
(dotimes (n 100000000)
(Incf acc (test-arg n cycle))
(incf cycle 7))))
(time
(let ((acc 0))
(dotimes (n 100000000)
(incf acc (test-dyn n))
(incf *cycle* 7))))
(time
(let ((acc 0)
(*cycle* 0))
(dotimes (n 100000000)
(Incf acc (test-dyn n))
(incf *cycle* 7)))))
It looks at three scenarios: straight argument passing, using a special variable with its default binding, and using a special variable with a local binding. The test functions themselves don't do anything sensible, just calculating a remainder to give them something to do in each call.
Comments on methodology welcome!
Seems the results won't fit, so I'll post in a reply...
