Re: Bitshifts and "And" vs Floor-division and Modular

Discussion in 'Python' started by Cameron Simpson, Sep 7, 2012.

  1. On 07Sep2012 01:30, Mark Lawrence <> wrote:
    | On 07/09/2012 01:01, jimbo1qaz wrote:
    | > Is it faster to use bitshifts or floor division? And which is better, & or %?
    | > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style?
    |
    | Why don't you use the timeit module and find out for yourself?

    Because timeit doesn't output style advice?
    Because timeit won't offer even a short single parapgraph description
    of how python ints (even just in CPython) are implemented and how that
    may affect performance in general?

    To the OP: personally, I would suggest using % when I am thinking of
    division and a bit shift when I am thinking of a bitshift, and only reach
    for timeit when performance becomes an issue. Code for the algoritm,
    and only optimise later.

    Of course only a well run benchmark will measure the real world, but it
    possible to address his other questions in a helpful fashion and address
    the benchmark question in a less offputting tone. If you can't be
    bothered, please don't. (Especially since these irritating posts from
    you are usually in response to a post you feel could have used more
    effort from the OP.)

    Nobody answers all performance considerations or design choices with an
    exhaustive timeit benchmark, and it is silly to suggest so. It is
    helpful for people to have a mental model of the python internals
    so they can make often-sensible choices from the start.

    So try being helpful instead of slapping people down when they haven't
    reached your private bar.

    Cheers,
    --
    Cameron Simpson <>

    Microsoft: Where do you want to go today?
    UNIX: Been there, done that!
     
    Cameron Simpson, Sep 7, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christoph Zwerschke

    Command line option -Q (floor division)

    Christoph Zwerschke, Mar 23, 2006, in forum: Python
    Replies:
    2
    Views:
    299
    Georg Brandl
    Mar 29, 2006
  2. Replies:
    9
    Views:
    761
    Andrey Tarasevich
    Oct 23, 2006
  3. Jeffrey Walton

    Division and Modular Reduction

    Jeffrey Walton, Jul 29, 2011, in forum: C++
    Replies:
    1
    Views:
    388
    Victor Bazarov
    Jul 29, 2011
  4. jimbo1qaz
    Replies:
    12
    Views:
    350
  5. Mark Lawrence
    Replies:
    0
    Views:
    207
    Mark Lawrence
    Sep 7, 2012
Loading...

Share This Page