argument-passing vs. dynamic variable lookup
Posted: Sat Oct 27, 2012 6:49 pm
For anyone who was curious as I was, I ran a quick and dirty test of the cost of doing dynamic variable lookups versus argument-passing.
Here's what I ran:
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...
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)))))
Comments on methodology welcome!
Seems the results won't fit, so I'll post in a reply...