so i used (time (power 234 34445))
and got the following results: nonrecursive:
8927
9434
8838
av: 9066msec recursive:
8826
9447
9493
av: 9255msec edit: then did this, better: nonrecursive: arc> (time (repeat 100(power 12 12345))) time: 20141 msec. nil recursive: arc> (time (repeat 100(power 12 12345))) time: 23484 msec. nil but consideriing the difference between each run it seems it could swing either way, too small a samplesize. but:
1) time isnt very reliable?
2) is there a better way to profile?
3) which are generally considered to be the fastest, recursive or imperative functions? (def power (nbr pow)
(if (is pow 0) 1
(> pow 0)
(let acc nbr
(for x 1 (- pow 1)
(= acc (* acc nbr))) acc)
(< pow 0)
(let acc 1
(for x pow -1
(= acc (/ acc nbr))) (/ acc 1.0))))
(def power (nbr pow)
(if (is pow 0)
1
(> pow 0)
(* nbr (power nbr (- pow 1)))
(< pow 0)
(/ 1 (power nbr (* -1 pow)))))
|