|
From: Per W. <pw...@ia...> - 2003-08-06 12:17:37
|
As Ioannis already mentioned, the important factor is if the compiler
knows the implementation of the function.
If the compiler has access to the code and can check that it returns a
constant value and doesn't have any side effects, it may - depending on
optimization settings etc - retrieve the end value before intering the
loop.
Whenever the compiler is in doublt, it has to assume that the function has
side effects or returns a nonconstant value, requiring the function to be
called - or the contents of the function to be inlined - for every
iteration of the loop.
/Per W
On Wed, 6 Aug 2003, OROSZI Bal=E1zs wrote:
> David McKen wrote:
> > Ok here is a test I tried on a OLD comp I have lying
> > around.
> >
> > System specifications:
> > 25Mhz 486 (no math co-processor)
> > 4Mb Ram
> > Compiled using the Pacific C compiler (djgpp runs WAY too
> > slow) using full
> > optimization.
> >
> > Program:
> > #include <stdio.h>
> > #include <time.h>
> >
> > long getint(void);
> >
> > int main()
> > {
> > time_t begin,end;
> > long i, get_int;
> >
> > begin =3D time(NULL);
> > for(i =3D 0; i < getint(); ++i);
> > end =3D time(NULL);
> > printf("Function call time taken =3D %i\n", end - begin);
> >
> > get_int =3D getint();
> > begin =3D time(NULL);
> > for(i =3D 0; i < get_int; ++i);
> > end =3D time(NULL);
> > printf("Varible buffer time taken =3D %i\n", end - begin);
> >
> > return 0;
> > }
> >
> > long getint(void)
> > {
> > return 50000000;
> > }
> >
> > Output:
> > Function call time taken =3D 40
> > Varible buffer time taken =3D 16
> >
> > Hope this helps.
>
> Thank you very much. Actually, I was also doing some benchmarks, and got
> the same result as you. However, that getint() function is not that
> simple :) It does something more complicated.
>
> Anyway, thanks for it.
>
> --
> Greetings,
> Bal=E1zs
>
>
>
> -------------------------------------------------------
> 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
>
|