|
From: Graham D. <g.d...@nt...> - 2003-08-05 18:43:33
|
Run the profiler to find out where the inefficiencies are. In my
experience, any attempt to prejudge optimisation will be wrong. The
inefficiencies are _never_ where you expect.
The two fundamental rules for optimising by hand are:
rule 1: don't do it.
rule 2: don't do it - yet.
OROSZI Balázs wrote:
> Hi!
>
> Now, I have a question.
> I need to do heavy optimizations in the project I am working on, and I
> am asking you, whether will I gain any speedup by optimizing loops. I
> am interested in the for loop exactly. Let's take this example:
>
> for(i=0;i<getint();i++){
> /* ... */
> }
>
> Would it worth it to take that getint() into an outer variable, and
> only use that in the conditional, like this:
>
> int c = getint();
> for(i=0;i<c;i++){
> /* ... */
> }
>
> Will this give me any speedup? I am interested in particular, is for
> going to call getint() EVERY time in the first case (on top), or will
> it do it only once? I think the second case is better, am I right?
>
> Allright, that was my first question, here is the second:
> What is the case, if the conditional is a KNOWN value. Something, like
> a macro. Here is the example:
>
> #define GETINT (10*5)
>
> for(i=0;i<GETINT;i++){
> /* ... */
> }
>
> I suppose, this will be optimised by the compiler, and this can even
> be unrolled, am I right?
>
> Thanks in advance.
> --
> Greetings,
> Balázs
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|