[racket] Why parameterize is so sloooow?
I compared parameterize with lexical var
----
> (require rackunit)
> (define my-parameter (make-parameter (box 0)))
> (time
(parameterize ([my-parameter (box 0)])
(for ([x (in-range 10000000)])
(set-box! (my-parameter)
(add1 (unbox (my-parameter)))))
(check-equal? (unbox (my-parameter)) 10000000)))
cpu time: 3578 real time: 3610 gc time: 0
> (time
(let ([my-parameter (box 0)])
(for ([x (in-range 10000000)])
(set-box! my-parameter
(add1 (unbox my-parameter))))
(check-equal? (unbox my-parameter) 10000000)))
cpu time: 47 real time: 47 gc time: 0
----
100 times difference!
The same experiment with Common Lisp (SBCL):
----
CL-USER> (setf *a* (list 0))
(0)
CL-USER> (time (progn (loop :for i :from 0 :below 10000000
:do (setf (car *a*) (+ 1 (car *a*)))) (= (car *a*) 10000000)))
Evaluation took:
0.063 seconds of real time
0.062500 seconds of total run time (0.062500 user, 0.000000 system)
98.41% CPU
172,464,541 processor cycles
0 bytes consed
T
CL-USER> (let ((a (list 0))) (time (loop :for i :from 0 :below 10000000
:do (setf (car a) (+ 1 (car a))))) (= (car a) 10000000))
Evaluation took:
0.047 seconds of real time
0.046875 seconds of total run time (0.046875 user, 0.000000 system)
100.00% CPU
132,098,942 processor cycles
0 bytes consed
T
----
Only 1.5 times.
Is it undesirable to use parameterize as replacement for common lisp special variables? What is it designed for then?
--
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130816/1c678193/attachment.html>