Slow UDF call?

Giovanni Di Maria calimero22 at yahoo.it
Sat Aug 17 19:43:22 UTC 2019


Hi,
i have seen that a simple operation (in a loop) is faster than 
the equivalent UDF.
The first example takes 4 seconds, the second example takes 16 
seconds.
Local variables influence the speed of execution?
Thank you very much.
Giovanni

======================================

import std.stdio;
void main()
{
     int a,b;
     int s;
     int k;
     writeln("START");
     for(k=1;k<=2_000_000_000;k++)
     {
         a=7;
         b=20;
         s=a+b;
     }
     writeln("Fine ",k," ",s);
}

======================================


import std.stdio;
void main()
{
     int a,b;
     int s;
     int k;
     writeln("START");
     for(k=1;k<=2_000_000_000;k++)
     {
         a=7;
         b=20;
         s=somma(a,b);
     }
     writeln("Fine ",k," ",s);
}

int somma(int n1,int n2)
{
     return n1+n2;
}




More information about the Digitalmars-d-learn mailing list