Notices
Results 1 to 4 of 4

Thread: Simple question: Does comparison use more processing power, or addition assignment operator?

  1. #1 Simple question: Does comparison use more processing power, or addition assignment operator? 
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    908
    Let me make it more specific!

    im gunna run through these likes of code a few hundred thousand times in my program, and im currently studying for code optimization.

    I'll show one for an example.

    I can either do:
    Code:
    if[key=='w'){
    keystrokes[key]=true;
    }
    or i can do:
    Code:
    keystrokes[key]=true;
    which takes less processing power?

    EDIT: oops the thread name is wrong, not addition assignment, but just assignment.


    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    Studying code optimization? As in an actual class, or just self study?

    Anyway, to answer your question, the second is obviously faster if key == 'w' and the first is almost certainly faster if key != 'w'. The actual differences depend on how often key == 'w' and what type keystrokes is. It also somewhat depends on where in your code this occurs.

    But either way, this is a micro-optimization and is almost certainly going to have almost no effect on performance. If this is self-study, you're kind-of headed in the wrong direction.


    Reply With Quote  
     

  4. #3  
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    908
    i was recently thought about linked list vs vector's code optimization. i was wondering about assignment operators half-way

    thx for the reply!
    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  5. #4  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    The STL is already highly optimized and tuned in ways that allow the compiler to make further optimizations. For common tasks, it would be very hard to do better performance-wise. That said, knowing which STL container to use when is an optimization worth knowing. And there are some tasks where more specialized data structures can outperform any of the STL classes.
    Reply With Quote  
     

Similar Threads

  1. Addition operator
    By JonG in forum Mathematics
    Replies: 5
    Last Post: September 4th, 2013, 02:08 PM
  2. Standard Addition Question
    By walker8476 in forum Chemistry
    Replies: 10
    Last Post: April 20th, 2013, 08:54 PM
  3. Power Balance of a Simple RC Circuit
    By Omnibus in forum Pseudoscience
    Replies: 37
    Last Post: March 14th, 2011, 05:31 AM
  4. Image Processing anD Signal Processing
    By apurba.das in forum Computer Science
    Replies: 1
    Last Post: November 23rd, 2009, 10:21 AM
  5. Processing Power
    By Mathwiz8390 in forum Computer Science
    Replies: 10
    Last Post: December 27th, 2005, 05:41 AM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •