"Aaron \"Castironpi\" Brady" <[EMAIL PROTECTED]> wrote:

> On Oct 5, 2:12 pm, "Aaron \"Castironpi\" Brady" <[EMAIL PROTECTED]>
> wrote:
>> Duncan Booth wrote:
>> > [EMAIL PROTECTED] wrote:
>>
>> > OFFSET = dict(("%x"%i, int(c)) for i,c in
>> > enumerate("5433222211111111")) def get_highest_bit_num(r):
>> >    s = "%x"%r
>> >    return len(s) * 4 - OFFSET[s[0]]
>>
>> OFFSET= tuple( int(x) for x in "5433222211111111" )
>> def get_highest_bit_num(r):
>>      s = "%x"%r
>>      return len(s) * 4 - OFFSET[int(s[0],16)]
> 
> That's really counterintuitive.  (That's the word, yes.)  They're both
> function calls and both global variables.  Maybe you could use 'len(s)
> * 4' to mask out the rest and lookup that index, rather than
> converting -back- to integer.  Or, better yet, take 'ord' of s[0].
> (Ha ha, -you- time it.)

No, the difference between the two is still an extra call to a global 
function.

'ord' may be slightly faster than calling 'int' (function calls with two 
arguments are slower than similar functions with only one), but you have 
still added one extra variable lookup and function call over the original.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to