Features of the mql5 language, subtleties and tricks - page 339

 

A forum on trading, automated trading systems and the testing of trading strategies

Features of the MQL5 language, nuances and techniques

fxsaber, 19 June 2022 16:17

For the specific case where a numeric field is used for sorting (the most common scenario), I’ve written a version that is several orders of magnitude faster than the previous one. However, it uses twice as much memory. This is relevant for large arrays.


Result.

Alert: Bench_Stack = 0, 100 <= Time[Test9.mq5 129 in OnStart: SortOnField_Num::SORT::Sort(Array)] = 34574468 mcs.

Alert: Bench_Stack = 0, 100 <= Time[Test9.mq5 130 in OnStart: SortOnField_Num::SORT2::Sort(Array)] = 10586 mcs.
It seems the reason for this result is that moving large structures between one another is much more costly during sorting than operating on indices.