efficiency of user-defined functions

 

I think somewhere in "The Book" if says having user defined functions is slightly less efficient (but much clearer to read and program). I'm wondering if I can use user defined functions while writing the EA, and then, when it's time to compile, copy and paste each function in place of the function call - inside the Start function. Has anyone tested if this is noticeably faster?

To my mind there are two possibilities:

1) The program flows in a linear way and each function is called only once in turn, and then finishing the Start function.. something like this:

int start()
   {
   Analyse();
   if(start) OpenOrder();
   if(quit) CloseOrder();
   return(0);
   }

My guess is... copying and pasting in the functions here definitely wouldn't INCREASE working time.. and might decrease it a little.

2) but then the other kind is less linear, or where you might have to copy in the same function in multiple places, e.g.:

int start()
   {
   Analyse();
   if(buy)
      {
      OpenOrder();
      Analyse();
      }
   if(sell)
      {
      CloseOrder();
      Analyse();
      }
   return(0);
   }

Do you think copying in the code for Analyse() three times might make the EA a little slower?

 
alladir: Do you think copying in the code for Analyse() three times might make the EA a little slower?
I would think it'll be about the same speed. I certainly wouldn't copy and paste the codes within the Analyse() three times. This is the reason the book recommended functions. When there's an action you repeat multiple times turn it into a function. You can test speeds by using the GetTickCount().
 
Thanks, it's what I was thinking. I'll test it later when I have time, and get back with the results........ though recently I'm starting to doubt the accuracy of GetTickCount()... but that's another issue.
 

I wouldnt do this. Stick to functions and writing good code.

In some tests I did calling an empty function 5,000,000 times added about 3.5 seconds to the execution speed.

That is a function call (with no parameters) took less than a millionth of a second. This was on a VM running on a fairly old host machine. (Q6600)

IF you have performance issues, then look at the algorithm, things that you are re-computing each tick etc.
 
ydrol:

I wouldnt do this. Stick to functions and writing good code.

In some tests I did calling an empty function 5,000,000 times added about 3.5 seconds to the execution speed.

That is a function call (with no parameters) took less than a millionth of a second. This was on a VM running on a fairly old host machine. (Q6600)

IF you have performance issues, then look at the algorithm, things that you are re-computing each tick etc.





ah nice work, thanks :]