Alternative implementations of standard functions/approaches - page 6

 
fxsaber:

Even the analogues are wildly divergent in terms of performance. The number of people who can write them or find them is less than a percentage of users.

Well, that's because the rest of people are quite happy with available performance ) In fact, frankly speaking, most of these speedups are appreciable only in isolated test measurements.

Of course, I don't argue that we should strive for perfection, but it's better to do it in order of priorities.

 
Alexey Navoykov:

Because other people are quite happy with available performance ) After all, most of these speedups are only noticeable in isolated test measurements.

Even a 1% gain in Optimization yields tangible results.

I certainly don't argue that you should strive for perfection, but it's advisable to do it in order of priority.

For MQ you are less interesting than the whole army of MT4 smart guys who for various reasons have not switched to 5.

 
Библиотеки: Fast iBarShift and Bars for MT5
Библиотеки: Fast iBarShift and Bars for MT5
  • 2018.05.04
  • www.mql5.com
Fast iBarShift and Bars for MT5: Автор: Nikolai Semko...
Files:
iBars.mqh  14 kb
 

Faster analogues of standard functions ceil(), floor(),round()

2-2.5 times speed advantage

long Ceil (double x) { return (x-(long)x>0)?(long)x+1:(long)x; }
long Round(double x) { return (x>0)?(long)(x+0.5):(long)(x-0.5);}
long Floor(double x) { return (x>0)?(long)x:((long)x-x>0)?(long)x-1:(long)x; }

Correctness and speed test results:

2018.08.25 17:23:23.199 TestRound (EURUSD,M10)  Время выполнения ceil =  3.745 наносекунд, Контрольная сумма = 5250492895
2018.08.25 17:23:23.200 TestRound (EURUSD,M10)  Время выполнения Ceil =  1.806 наносекунд, Контрольная сумма = 5250492895
2018.08.25 17:23:23.205 TestRound (EURUSD,M10)  Время выполнения floor = 4.243 наносекунд, Контрольная сумма = 5249492896
2018.08.25 17:23:23.206 TestRound (EURUSD,M10)  Время выполнения Floor = 1.621 наносекунд, Контрольная сумма = 5249492896
2018.08.25 17:23:23.209 TestRound (EURUSD,M10)  Время выполнения round = 2.984 наносекунд, Контрольная сумма = 5249992896
2018.08.25 17:23:23.211 TestRound (EURUSD,M10)  Время выполнения Round = 1.519 наносекунд, Контрольная сумма = 5249992896
The standard functions return type double. But I didn't repeat it because I don't understand why rounded functions need the type double.
Files:
TestRound.mq5  5 kb
 
Nikolai Semko:

the results of the correctness and speed test:

Only not nano, but miles.

 
fxsaber:

Only they are not nano, they are miles.

No nano. 1000000 passes, and I divide it by 1000.
Only they are even faster, as they are counted together with all the contents of the loop pass. I will get to my computer in 3 hours and fix the runtime calculation for purely these functions.
 
Nikolai Semko:
No nano. 1000000 passes, and I divide it by 1000.
An ambiguous interpretation then. Decided to output the cycle time, not the average time per function call.
 
fxsaber:
Ambiguous interpretation then. Decided to output the cycle time, not the average time of one function call.
Yes, this time still includes the time to do three additions and 1 check.
I'll fix it, because I know how. So the gain will be even greater.
 
Nikolai Semko:
The standard functions return type double. But I didn't repeat it because I don't understand why rounded functions need the type double.

Because converting double to integer (this way) is shitty code. Round with friends is not designed to get integer type from floating type.