Re: [CHALLENGE] finding rightmost zero bit





Bart Vandewoestyne wrote:
OK folks, time for a new challenge...

My profiler tells me that findpos(n) is a function which my code
seems to be using.  The function looks like:

  function findpos(n) result (pos)

    integer(kind=i4b), intent(in) :: n
    integer(kind=i4b)             :: pos

    ... do your private stuff here ...

  end function findpos

and its purpose is to find the index of the rightmost zero bit in the
base 2 representation of a number n.  The least significant bit has
position 1.

The exact `Mission' of the challenge and a template-file can be
found at

http://www.cs.kuleuven.ac.be/~bartv/stuff/time_findpos.f95

I have three versions, and which one wins seems to depend a bit
on compiler and architecture...

bartv@vonneumann:~/fortran$ ./time_findpos huge(n) is 2147483647.
Enter first number: 1
Enter last number: 147483647
Bart1's method did it from 1 to 147483647 in 1.69 seconds.
Bart2's method did it from 1 to 147483647 in 1.79 seconds.
Bart3's method did it from 1 to 147483647 in 1.72 seconds.


I think these are already quite fast and can probably not be speed up quite
a lot, but this newsgroup has learned me that i should *never* think my
routines can't be speeded up anymore... so amaze me, and be faster! :-)

Challenge ends this sunday at 23h59 your local time :-)

Regards,
Bart


Times on my system vary a lot (up to 20%) from one run to the other, and I suspect that since 50% of your test cases have pos=1 and 25% more pos=2, the function is then so fast that you are measuring only function call overheads. As a test, I tried to call my function directly from time_findpos, and it reduced its time by 45%, and even 60% when I directly inserted the function code into time_findpos.

I believe the challenge is to find a fair way to time that function.
:-)

.