Getting the bar opening time (SERIES_LASTBAR_DATE) having the position opening time - page 2

 
Marcin Madrzak #:

On my PC it takes about 0.00000000025 s to validate a boolean value in a loop. It's an average calculated on a loop of 1.000.000.000 iterations. The control loop was empty. Now check the ping to your broker's server and the average server execution time of the trade and you will know that you should be much more concerned about other aspects than this. ;)

Your "benchmarks" are not valid as such code will be optimized by the compiler. You are measuring nothing.
 
Marcin Madrzak #:

On my PC it takes about 0.00000000025 s to validate a boolean value in a loop. It's an average calculated on a loop of 1.000.000.000 iterations. The control loop was empty. Now check the ping to your broker's server and the average server execution time of the trade and you will know that you should be much more concerned about other aspects than this. ;)

250 pico seconds. That is still 25 clock cycles on a 3.5GHz CPU. Seems a bit much. If I remember right, the comparison instruction on a x86 CPU for two registers takes 2 CPU cycles.

EDIT:

The main problem with branching code is the predictability of the branch. If the prefetcher unit of the CPU is able to predict the correct path, it will actually only take 2 CPU cycles. But if the prediction fails, a cache invalidation and a full new fetch cycle are required to compensate the false prediction. That will take much longer than 25 CPU cycles.

To prevent false branch prediction, you can use constant variables.

 
Dominik Egert #:
250 pico seconds. That is still 25 clock cycles on a 3.5GHz CPU. Seems a bit much. If I remember right, the comparison instruction on a x86 CPU for two registers takes 2 CPU cycles.


Yes, as i said, i better avoid useless checks that are supposed tu just run ONCE, coded it into OnInit, if something fails it justs sleeps for a moment and try again, works good.