On 2006-01-05, Simon Kr?ger <SimonKroeger / gmx.de> wrote:
> Lou Vanek wrote:
>
>> The shift operator comes in handy and can save a lot of time.
>> These are equivalent operations:
[snip 3 examples with considerable speed differences]

>
> This is an implementation detail,

perhaps.
I'd say ** takes *more* time; not that bitshifts take *less* time.

> the ** operator of Fixnum calls rb_big_pow converting self to a Bignum 
> regardless of the value. '<<' checks the size of the result and uses 
> real bitshifting if possible.

worse:
kero@chmeee:~$ time ruby -e '100_000.times { ||  200**10 }'

real    0m1.740s
user    0m1.540s
sys     0m0.072s
kero@chmeee:~$ time ruby -e '100_000.times { ||  2**10 }'

real    0m2.122s
user    0m1.928s
sys     0m0.064s

The float value ranks first with about 0.5 seconds runtime.

If Fixnum#** is slower than Bignum#**, that's not a detail, that's plain
weird :)

Something to keep in mind...

Bye,
Kero.