I recently wrote a program which involved taking the
square roots of a sequence of numbers until one of them was
found to be an integer. In about half of these cases, all the
numbers in the sequence were multiples of 4, and it occurred to
me that I could work with the numbers divided by 4, instead of
as they first occurred in the sequence. I expected this to
produce a (tiny) increase in speed. However, the main loop of
the program appears to take 16/15 as long to find the integer as
it did before, and that's before you take into account the mult.
and div. by 4 at the start and end.
I'm using PowerBASIC 3.2 for DOS. My machine is a 133MHZ
Pentium. The metastatements I used were:
$FLOAT NPX
$CPU 80386
$OPTIMIZE SPEED
(it occurs to me that $CPU 80486, $CPU PENTIUM, etc. would be
good metastatements for future versions.)
The loop kept repeating these two lines:
40 incr s&&, v&&: incr v&&, x: s##=sqr(s&&): if s##=int(s##) then 50
45 goto 40
Now, I think that the most likely explanation for the loss of
speed is that the square root algorithm is taking longer, so
my first question is: can anybody think of another reason?
Secondly, I know that root extraction involves an iteration.
Does anyone know what starting value PB uses for this iteration
when trying to extract the square root of a quad integer? Plus,
does anyone know what algorithm PB uses to extract the root?
This is mainly to help me find out what happened, but also
because I'd like to construct my own square root algorithm that
would allow the user to specify the iteration's start value.
Finally, is there any way to purchase the source code for your
version of PB? This is standard practice for vendors of C and
C++ and doesn't appear to have done their sales any harm.
Thanks,
James McLaughlin.
square roots of a sequence of numbers until one of them was
found to be an integer. In about half of these cases, all the
numbers in the sequence were multiples of 4, and it occurred to
me that I could work with the numbers divided by 4, instead of
as they first occurred in the sequence. I expected this to
produce a (tiny) increase in speed. However, the main loop of
the program appears to take 16/15 as long to find the integer as
it did before, and that's before you take into account the mult.
and div. by 4 at the start and end.
I'm using PowerBASIC 3.2 for DOS. My machine is a 133MHZ
Pentium. The metastatements I used were:
$FLOAT NPX
$CPU 80386
$OPTIMIZE SPEED
(it occurs to me that $CPU 80486, $CPU PENTIUM, etc. would be
good metastatements for future versions.)
The loop kept repeating these two lines:
40 incr s&&, v&&: incr v&&, x: s##=sqr(s&&): if s##=int(s##) then 50
45 goto 40
Now, I think that the most likely explanation for the loss of
speed is that the square root algorithm is taking longer, so
my first question is: can anybody think of another reason?
Secondly, I know that root extraction involves an iteration.
Does anyone know what starting value PB uses for this iteration
when trying to extract the square root of a quad integer? Plus,
does anyone know what algorithm PB uses to extract the root?
This is mainly to help me find out what happened, but also
because I'd like to construct my own square root algorithm that
would allow the user to specify the iteration's start value.
Finally, is there any way to purchase the source code for your
version of PB? This is standard practice for vendors of C and
C++ and doesn't appear to have done their sales any harm.
Thanks,
James McLaughlin.
Comment