Thread: efficiency of a programming

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User sureshhewa's Avatar
    Join Date
    May 2008
    Location
    sri lanka
    Posts
    13

    Post

    ok. think of it this way. now i have to write a programme. I have 2 strategies to solve it.
    1.I can use an extra structre array which will allocate160bytes
    2. I can put nested loop which will be loop 100 times

    so what should i choose. I know it is depend on the problem. When a good programmer face to this matter what are the facts he/she must consider?? any rough idea??

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by sureshhewa View Post
    ok. think of it this way. now i have to write a programme. I have 2 strategies to solve it.
    1.I can use an extra structre array which will allocate160bytes
    2. I can put nested loop which will be loop 100 times

    so what should i choose. I know it is depend on the problem. When a good programmer face to this matter what are the facts he/she must consider?? any rough idea??
    Time means that you can do something quickly.
    Memory means that you can do a lot of things at once.
    In cases where you want both, you have to compromise. But the choices then depend directly on how much you want each of those two things; if you want to do things quickly, prefer fewer loops; if you want to do many things at once, prefer less memory.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    In some cases, if your code complexity is already optimized pretty well but your code it huge, you could speed up your program by making it smaller. If all or most of your code can fit into the CPU cache, it will reduce the need to access RAM which is slower than cache.
    Most modern compilers are smart enough to choose the right blend of size/speed optimizations to run in the best way for your CPU.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Efficiency with c++
    By pastitprogram in forum C++ Programming
    Replies: 17
    Last Post: 08-08-2008, 11:18 AM
  2. Calculating space efficiency using sizeof()
    By markcls in forum C Programming
    Replies: 6
    Last Post: 05-19-2007, 05:25 AM
  3. Efficiency problems
    By Crazy Glue in forum C# Programming
    Replies: 15
    Last Post: 07-20-2006, 08:38 AM
  4. Programme Efficiency
    By Cikotic in forum C Programming
    Replies: 3
    Last Post: 06-28-2004, 01:29 PM
  5. Binary tree search efficiency
    By ExCoder01 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-23-2003, 10:11 PM