I'm trying to show the result I'm after by showing the what I don't want. Here is the code I'm referring to, the way the functions work don't matter...I highlight how long it takes to run, them and that is what matters. Just keep an out because 2 functions in my question have names that are exactly the same except for a % at the front of it's name.
Code: Select all
(let ((val nil))
(defun c-arr-to-vector-float (a len)
(cond (val val)
((listp a) (progn (setf val (foreign-alloc :float :initial-contents a))
(%c-arr-to-vector-float val len)))
(t nil))))
If I run this:
Code: Select all
(%c-arr-to-vector-float (foreign-alloc :float :initial-contents '(1 2 3)) 3 )
1 million times, it takes 6 seconds. but if define
Code: Select all
(foreign-alloc :float :initial-contents (1 2 3))
first like:
Code: Select all
(defparameter a (foreign-alloc :float :initial-contents '(1 2 3)))
then run
running
only takes .017 seconds...do you see where I'm coming from here...I'm looking to speed up the above function? but each time I run the
with the let statement above I have to be able to put in a new value, i.e. every time this is run
Code: Select all
(c-arr-to-vector-float '(1 2 3) 3)
(that's name of the defun in the let) the function should operate on the '(123) and if I give it a '(4 5 6) it should operate on that. And I don't want to make someone run the defparameter first each time, I'm trying to make it be automatic and everything inside one s-expression.