Speed

This is a discussion on Speed within the C++ Programming forums, part of the General Programming Boards category; Hey everyone. You know how simple operations take different speeds? For example, addition takes less time than division. Reading takes ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    73

    Speed

    Hey everyone. You know how simple operations take different speeds? For example, addition takes less time than division. Reading takes less time than assigning. (I think) (You get the point)

    Is there some sort of table that can tell me the speeds? Or a way I can determine it? I'm trying to make a processor-intensive area faster, and I came on this problem:

    Is it faster like this...
    Code:
    int Operation( int A, int B )
    {
       int C = A + B;
       return C * C;
    }
    or...
    Code:
    int Operation( int A, int B )
    {
       return ( A + B ) * ( A + B );
    }
    It's a question of which is faster, two additions or making another integer.


    So is there some sort of table somewhere? Or a way I can find out the speeds of these operations?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    It doesn't matter which is faster. Choose the one that is clearer (as long as they are close in efficiency).

    If you really want to know, you can do performance tests to see.

    I don't know of any table or resource that has that information right at hand, though. You kind of have to pick up on things as you learn.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Just run each operation a 100 million times in a for loop and time it yourself. I seriously doubt you'll find even the slightest bit of difference in time.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    One way to check, if you're using gcc, is to use the -S flag and compare the resulting assembly that is generated.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 11:29 AM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2006, 11:40 PM
  3. Replies: 6
    Last Post: 01-08-2006, 01:49 PM
  4. increased net speed
    By PING in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-29-2005, 06:05 AM
  5. Questions on Speed of Execution
    By wavering in forum C Programming
    Replies: 22
    Last Post: 01-20-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21