Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^7: code optimization

by spx2 (Chaplain)
on Nov 04, 2011 at 15:27 UTC ( #935961=note: print w/ replies, xml ) Need Help??


in reply to Re^6: code optimization
in thread code optimization

Yeah, I guess my results show division is a bit slower(on most runs, just on one of 'em it was actually faster)

Maybe it's possible to tell the compiler to not jump to optimizations.

Also, isn't 1*i a bit too easy ?


Comment on Re^7: code optimization
Re^8: code optimization
by BrowserUk (Pope) on Nov 04, 2011 at 16:10 UTC
    Also, isn't 1*i a bit too easy ?

    I assume(d) the microcode should go through the same sequence of steps regardless of the values of its operands, but maybe it is being optimised because changing it does reduce the differential between mult & div:

    C:\test>muldiv-b 1000000000 integer multiplications: (by 12345)Took 3697 ticks C:\test>muldiv-b 1 1000000000 integer divisions:(of 12345) Took 3400 ticks C:\test>muldiv-b 1000000000 integer multiplications: (by 12345)Took 3697 ticks C:\test>muldiv-b 1 1000000000 integer divisions:(of 12345) Took 3432 ticks

    But if it is being optimised away, for it to make so little difference to the result would mean the benchmark is totally crap.

    Which I now believe to be the case. The opcodes involved in running the loop are just swamping the cost of the actual mult/div opcodes to the point where they are just noise. The only way to really verify my memory that they take the same number of clocks, would be to drop into assembler and I'm not interested enough to do that.

    On pipelined processors such measurements are always iffy anyway because it will depend upon what else is in the pipeline, whether the processor stalls for caching; and a whole bunch of other stuff.

    The bottom line is that I do not think that there is sufficient differential between mult & div to make a two mults approach viable.

    And IO is going to dominate the OPs code whatever he does.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-09-21 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls