Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I did a similar thing using C:

#include <stdio.h> #define ITERS 1000000000ul int main( int argc, char **argv ) { __int64 start; int i; double d; getch(); start = GetTickCount64(); if( argc > 1 ) { printf( "%u integer divisions: ", ITERS ); start = GetTickCount64(); for( i = 1; i < ITERS; i++ ) d = 1 / i; printf( "Took %I64d ticks\n", GetTickCount64() - start ); } else { printf( "%u integer multiplications: ", ITERS ); start = GetTickCount64(); for( i = 1; i < ITERS; i++ ) d = 1 * i; printf( "Took %I64d ticks\n", GetTickCount64() - start ); } }

And on my 64-bit processor, for 32-bit ints I got:

C:\test>muldiv-b 1 1000000000 integer divisions: Took 3432 ticks C:\test>muldiv-b 1000000000 integer multiplications: Took 2917 ticks

The numbers vary ~+-30 ticks for individual runs, but division is always ~10% slower than multiplication. I put this down the subsequent promotion of the result to a double rather than the opcode itself.

Conversely, if I use 64-bit ints division is almost 7X slower than multiplication:

C:\test>muldiv-b 1000000000 integer multiplications: Took 3011 ticks C:\test>muldiv-b 1 1000000000 integer divisions: Took 20764 ticks

This is think is due to the fact that two 64-bit registers are involved in the result.


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.

In reply to Re^6: code optimization by BrowserUk
in thread code optimization by arivu198314

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-19 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found