Hi Lindsay,

> Having just tried it... I am surprised that the 'sqrt*  I implemented is
> quite a bit faster! than the built-in 'sqrt. I'll try the long division
> later.

Wow, that's indeed a bit surprising. However, it depends on the scale, and I
think a can explain (see below).

> : (scl 100000) (bench (nil (sqrt 2.0)))   # Built-in
> 30.917 sec
> -> NIL
> : (scl 100000) (bench (nil (sqrt* 2.0)))   #
> 2.906 sec

Which scale did you use here? If I try 2

   : (scl 2)
   -> 2

   : (bench (do 1000000 (sqrt 2.0 1.0)))  # Built-in
   0.106 sec
   -> 141

   : (bench (do 1000000 (sqrt* 2.0)))
   5.052 sec
   -> 141

and then bigger ones,

   : (scl 20)
   -> 20

   : (bench (do 100000 (sqrt 2.0 1.0)))  # Built-in
   1.435 sec
   -> 141421356237309504880

   : (bench (do 100000 (sqrt* 2.0)))
   6.103 sec
   -> 141421356237309504880

the built-in is a quite faster.


But for bigger scales

   : (scl 64)
   -> 64

   : (bench (do 10000 (sqrt 2.0 1.0)))  # Built-in
   1.269 sec
   -> 14142135623730950488016887242096980785696718753769480731766797380

   : (bench (do 10000 (sqrt* 2.0)))
   0.762 sec
   -> 14142135623730950488016887242096980785696718753769480731766797379

the built-in is slower.


I think this is because the built-in 'sqrt' first multiplies with the scale
(just as we do before a division), and thus calculates with bignums of double
length.

I think this is necessary for a precise result.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to