GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Aug-2005, 10:39
gaoanyu gaoanyu is offline
Awaiting Email Confirmation
 
Join Date: Jun 2005
Location: Bristol, UK
Posts: 26
gaoanyu is on a distinguished road

Compiled executable speed


Dear friends,

I need to optimize a C++ project (or in particular a video Decoder) so that after compilation, the executable (Under DOS) can work faster than before (for it to work for Internet streaming applications). I think in this case, which compiler to choose is definitely an issue, does anyone have any idea about this? Furthermore, can you give me some suggestions as what types of source code writing styles (how to structure loops, how to access class members etc) could speed things up? Besides, are there any other major points that I should pay attention to when trying to speed up things? Sorry for so many questions, any comment is highly appreciated!

Best regards,
David
  #2  
Old 18-Aug-2005, 20:09
maprich maprich is offline
Member
 
Join Date: May 2005
Posts: 163
maprich has a spectacular aura aboutmaprich has a spectacular aura about
Quote:
Originally Posted by gaoanyu
Dear friends,

I need to optimize a C++ project (or in particular a video Decoder) so that after compilation, the executable (Under DOS) can work faster than before (for it to work for Internet streaming applications). I think in this case, which compiler to choose is definitely an issue, does anyone have any idea about this?
Some compiler expert reading this please answer in greater detail.

I only know that to gain optimum performance from compiler.
You compile with release settings instead of debug settings with selecting maximum compiler optimizations. The 'release' version settings is essentially the same as omitting debug information as the debug setting creates (after linking) an executable that includes many additional information for the debugger.
Most compilers also allow processor specific optimizations for instruction set. (e.g. x486, x586, Pentium4, MMX extension - most traditional being x386 set of instructions) .. this can make your code more effective if you e.g. optimize for pentium4 but then it may not run at all in previous processors.
Quote:
Originally Posted by gaoanyu
Furthermore, can you give me some suggestions as what types of source code writing styles (how to structure loops, how to access class members etc) could speed things up?
Well if speed is an issue then note that pure C is more eficient than C++. In C++ the handling of classes requires more complicated work than C struct's and functions.
About the "code writing style" the key factors are:
  1. What kind of algorithm you are using. In computing science you say that your algorithm executes in
    1. linear time: Time = f(n)= a*N + b, where N is the size of the data to process. a, b some constants specific to your algorithm
    2. logarithmic time: f(n) = a*log( N, base) + b
    3. exponential time: f(n) = a*b^N + c
      e.g. a for-loop that iterates from 0 to N and where one iteration takes always standard time X regardless on the processed data and where N is exactly the amount of processed data will be an algorithm that executes in linear time..
      In many cases a distinction between "worst case scenario time" and "average time" can be made for algorithms. e.g. for sorting algorithms

      So naturally you try to find such solutions to your problems that require the absolute minimum amount of processing.
  2. Where your program spends most its time
Quote:
Originally Posted by gaoanyu
Besides, are there any other major points that I should pay attention to when trying to speed up things?
Besides the algorithm optimization:
you can compile with debug options after which you analyze with debugger where your program spends most of its time. (which function, which loop)
if you cannot optimize the C code any further then you may consider writing the performance critical part in inline assembly.
Quote:
Originally Posted by gaoanyu
Sorry for so many questions, any comment is highly appreciated!
No trouble at all. We ask so that we may learn.
  #3  
Old 19-Aug-2005, 19:34
Atomical Atomical is offline
New Member
 
Join Date: Jul 2005
Posts: 25
Atomical has a little shameless behaviour in the past
You can use gprof if you're on linux to track performance on a function level. I also have a question on optimizing.

Will the compiler optimize this?

strlen("STUFF");

Would the compiler create a variable for the strlen variable so it doesn't call it twice?

char *a = malloc(2000*strlen(v));
char *b = malloc(2000*strlen(v));
  #4  
Old 23-Aug-2005, 09:15
gaoanyu gaoanyu is offline
Awaiting Email Confirmation
 
Join Date: Jun 2005
Location: Bristol, UK
Posts: 26
gaoanyu is on a distinguished road
Dear Maprich,

Many thanks to your reply, it's been very helpful, it points out directions where I should follow. I'll take some time to think about these points in detail and then post my thoughts, thanks again.

Atomical, thanks for you reply too. Unfortunately, I don't have access to a linux machine, so.. but I was told that I could use Inter Complier to view the performance on the function level in Windows, so maybe I should go from here. ;-)

david
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What AGP speed do I have? crassbones Computer Hardware Forum 3 22-Dec-2004 18:37
*executing problems mattchew008 C++ Forum 1 14-Nov-2004 01:25
Download speed limit Maniac Apache Web Server Forum 1 09-Mar-2004 04:40
Alexa testing site speed - Desilva.biz in top 1% ! jrobbio Web Hosting Forum 5 17-Jan-2004 18:30
Could you test the speed of this domain for me jrobbio Websites Reviewed Forum 8 21-Jan-2003 14:24

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:28.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.