digitalmars.D.learn - Slow UDF call?
- Giovanni Di Maria (44/44) Aug 17 2019 Hi,
 - Stefan Koch (8/52) Aug 17 2019 Yes they do
 - Giovanni Di Maria (7/16) Aug 17 2019 Hi Stefan Koch
 - Giovanni Di Maria (6/24) Aug 17 2019 I have also compiled with:
 - H. S. Teoh (10/14) Aug 18 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;
}
 Aug 17 2019
On Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria 
wrote:
 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;
 }
Yes they do
A function call has a cost.
In case of a function which performes a 1 cycle  (nominally 
without ILP) operation, the overhead of the function call 
dominates.
try compiling with -inline and compare again.
 Aug 17 2019
On Saturday, 17 August 2019 at 20:15:02 UTC, Stefan Koch wrote:On Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria wrote:Hi Stefan Koch Thank you very much. With the option -inline, now the execution is very fast, only 4 seconds.... Thnak you thank you very much. Giovanni[...]Yes they do A function call has a cost. In case of a function which performes a 1 cycle (nominally without ILP) operation, the overhead of the function call dominates. try compiling with -inline and compare again.
 Aug 17 2019
On Saturday, 17 August 2019 at 20:57:44 UTC, Giovanni Di Maria wrote:On Saturday, 17 August 2019 at 20:15:02 UTC, Stefan Koch wrote:I have also compiled with: dmd program.d -O -release -inline -boundscheck=off and the execution speed is very very fast. GiovanniOn Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria wrote:Hi Stefan Koch Thank you very much. With the option -inline, now the execution is very fast, only 4 seconds.... Thnak you thank you very much. Giovanni[...]Yes they do A function call has a cost. In case of a function which performes a 1 cycle (nominally without ILP) operation, the overhead of the function call dominates. try compiling with -inline and compare again.
 Aug 17 2019
On Sat, Aug 17, 2019 at 09:42:00PM +0000, Giovanni Di Maria via Digitalmars-d-learn wrote: [...]I have also compiled with: dmd program.d -O -release -inline -boundscheck=off and the execution speed is very very fast.[...] If performance is important to you, I recommend checking out LDC. IME, it consistently produces code that outperforms dmd-generated code by about 20-30%, sometimes even as high as 40-50%, depending on the nature of your code. T -- Never ascribe to malice that which is adequately explained by incompetence. -- Napoleon Bonaparte
 Aug 18 2019








 
 
 
 "H. S. Teoh" <hsteoh quickfur.ath.cx>