[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] call-with-values speed

From: Zbigniew
Subject: [Chicken-users] call-with-values speed
Date: Tue, 22 Nov 2005 01:47:12 -0600

I would like to pass along an observation on returning multiple
values.  I wrote a C function that needed to return two values to
scheme, an int and a pointer.  Ultimately, I allocated a scheme object
for the pointer prior to the call, passed it as an argument, then
manipulated the contents in C, "passing" it back---as is the common
idiom.  But for a while I toyed with other ways to do this, such as
returning multiple values.

Unfortunately, I found that handling multiple values is very slow.  In
fact, if you cannot use the method I mentioned above (the fastest), it
is much faster to construct and deconstruct a list or cons with 2
values than to process multiple values.  I provide some timing below. 
I do not personally care if values are fast, as I have other
satisfactory workarounds; it is just interesting.  I didn't find any
mention of it in the mailing list archives, though.

These were typed at the csi prompt.

;; bare loop for timing baseline:

;; (define (q n) (if (fx= n 0) 'done (q (fx- n 1))))
;; #;7> ,t (q 1000000)
;;    1.252 seconds elapsed
;;   6.e-03 seconds in (major) GC
;;        3 mutations
;;     1683 minor GCs
;;        5 major GCs

;; loop returning 2 values:

;; (define (t n) (if (fx= n 0) 'done (begin (##sys#call-with-values
(lambda () (values 1 2)) (lambda (a b) (void))) (t (fx- n 1)))))

;; #;8> ,t (t 1000000)
;;   44.275 seconds elapsed
;;    8.196 seconds in (major) GC
;; 22000002 mutations
;;       47 minor GCs
;;     5864 major GCs

;; loop constructing and deconstructing a 2-element list:

;; (define (t n) (if (fx= n 0) 'done (begin (let* ((L (list 1 2)) (a
(car L)) (b (cadr L))) (void)) (t (fx- n 1)))))
;;    3.857 seconds elapsed
;;    0.302 seconds in (major) GC
;;        2 mutations
;;      179 minor GCs
;;      219 major GCs

reply via email to

[Prev in Thread] Current Thread [Next in Thread]