Division and right shift in python

Cevahir Demirkıran cevomed at gmail.com
Wed Aug 26 01:48:52 CEST 2009


I would like to do a floor division by a power of 2 in python to make it
faster than / (modular division in 2.x).
However, it is slower.
What is the reason of that?
I checked them via:

 def f2(x,n):
    t1 = clock()
    r = x/pow(2,n)
    t2 = clock()
    print (t2-t1)
    print r
    t2 = clock()
    r = x>>n
    t3 = clock()
    print (t3-t2)
    print r
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090826/13e2743c/attachment.html>

More information about the Python-list mailing list