2**HUGENUMBER Why not optimise it?
Tim Peters
tim.one at comcast.net
Thu May 23 14:22:27 EDT 2002
[Mike C. Fletcher]
> Oh. Sigh.
>
> Maybe I'll just give up on trying to interest people in Python
> optimisation challenges. The good-old days of idle speculation and
> optimisation are dead. Time to stop living in the past. Idea dropped,
> back to boring GUI work.
Ya, but "optimizing" 2**N to a shift is like, instead of trying to speed
flattening of arbitrary nested sequences, trying to speed flattening of a
list nested no more than 3 deep, whose first element is a non-nested tuple,
there are no more than 4 elements in all, and the last list element is an
int. Face it: it's boring <wink>.
[Christian Tismer]
> Don't say such sad words.
> Nothing is dead but maybe some of our expectations.
> Python was never eager to adopt new features (which
> is good), but putting ideas down this short wasn't
> usual, too.
It's truly trivial for a user to a write a shift themself, and long-int pow
is almost always used in real life in its 3-argument form, where this
optimization doesn't apply (except to waste cycles determining that it's of
no use). Now you know perfectly well that it's possible to write a simple
pow() in Python that runs faster than the current C version in *many*
cases -- that's a lot more interesting.
[Michael Hudson]
> Do you feel like implementing Karatsuba multiplication in
> longobject.c? That might actually be some use...
[back to Christian]
> Although this was on the table two or three years
> ago, and dissed as well, although cheap to implement.
I don't recall it being dissed. I do recall that nobody cared enough at the
time to write a patch to do it. Hell, we still don't have a reasonable,
cheap way to determine the number of significant bits in a long, although
for 2.2 math.log and math.log10 were generalized to work on arbitrary longs,
and math.log(n)/math.log(2) is a darned good guess now.
>>> x = 1L << 1000000
>>> import math
>>> math.log(x)
693147.18055994529
>>> _/math.log(2)
1000000.0
>>>
you-can't-change-history-when-a-bot-is-watching<wink>-ly y'rs - tim
More information about the Python-list
mailing list