in reply to Re^2: An array of boolean values in a bitfield
in thread An array of boolean values in a bitfield

I get it, so @sum and %bits_in have the same purpose!

I'm just confused, why do you care about the speed to calculate a constant table with only 256 entries? And why do you use a hash if speed counts? ... arrays are much faster!

Cheers Rolf

  • Comment on Re^3: An array of boolean values in a bitfield

Replies are listed 'Best First'.
Re^4: An array of boolean values in a bitfield
by kyle (Abbot) on Dec 03, 2008 at 18:22 UTC

    I'm not trying to optimize the creation of the lookup table. The lookup table is used to (more quickly) count bits in the bit field. I don't use an array for that because then the lookups would have to call ord to get the index into the array.

      I'm still confused, ... UPDATE: after rereading the code my confusion vanished, (but I'm better leaving the monastry till this starting flue doesn't affect my concentration anymore ;)

      Anyway an extra ord() should be faster than any internal hashfunction. I'm not sure about the usecase, but if you want to tie the functionality, the additional ord() wouldn't bother the user of your module.

        Anyway an extra ord() should be faster than any internal hashfunction.
        You can closely estimate the efficiency of perl code by counting the number of simple operations, and an ord() and array lookup is one more operation than a hash lookup. I would expect it to be about 25% slower. Feel free to benchmark, though.