speed of process: function() vs (global variable) vs (static variable) . I need ADVICES !

 

I started coding just several months ago and so have little experience.

Query 1:

In programs that some index is used (called) many times at anywhere, we can create either a function or a global variable to calculate that index.


Please advise me if a function or a global var is better for speed of program running

Query 2:

Global var and local static var are both possible to be used within a function (for the same purpose)


Please advise me if which is less harmful to speed of program running.


Thank you very much for sharing your experience. Welcome unlimited advices !

 

You may be confusing the scope of a variable with global variable.

A variable placed between last extern and the first special function, which which are init() start() and deinit(), has the scope of the whole program where a Global variable can be accessed by other EA's running on different charts.

Timing of variable access is reasonably insignificant - function calls can add to program timing but make programs so much easier to read and increase quick change felixibity that using a function is preferable to not using one.

Reason: