OK! Here it is and I will leave it up to you to draw your own conclusions:
Hello,
Yep, it seems there is not any gain from going 32bit; but we shall pay attention, float/double division is slower than the integer one. Also, slower floats in your example can show us that in modern hardware it may be better to work on the native bit width. However one should keep in mind that with lower bits, e.g. with ints or shorts, one can have the chance to vectorise and gain additional speed
Demos Stogios: Yep, it seems there is not any gain from going 32bit; but we shall pay attention, float/double division is slower than the integer one. Also, slower floats in your example can show us that in modern hardware it may be better to work on the native bit width. However one should keep in mind that with lower bits, e.g. with ints or shorts, one can have the chance to vectorise and gain additional speed
Yes, I agree! The best will be for the coder/user to always test his own implementations and decide which is best for the individual case!
So I ran the scripts (1E8 iterations), once again :-D
We can easily when the script started, finished and that all 4 logical processors where used at 100%. I also checked the MT5 threads, and I confirm there was only 1 additional thread while the script was running.
Conclusion: 1 thread can used 100% of all cores. I was not aware about that.
What I couldn't understand was why the execution time is multiplied by 100 when the iterations are just multiplied by 10 (hardcoded in script, so recompiled between the 2 runs).
2018.01.16 17:54:06.223224626_2 (NZDUSD,H1)<int>: 37 ms for 10000000 iterations
2018.01.16 17:54:06.251224626_2 (NZDUSD,H1)<double>: 27 ms for 10000000 iterations
2018.01.16 17:59:14.606224626_2 (NZDUSD,H1)<int>: 3545 ms for 100000000 iterations
2018.01.16 17:59:18.672224626_2 (NZDUSD,H1)<double>: 4062 ms for 100000000 iterations
So I changed the script a bit to use an input parameter to select the iterations count, instead of it being hardcoded. And surprise :
2018.01.16 18:04:02.855224626_2 (NZDUSD,H1)<int>: 34 ms for 10000000 iterations
2018.01.16 18:04:02.887224626_2 (NZDUSD,H1)<double>: 31 ms for 10000000 iterations
2018.01.16 18:03:53.974224626_2 (NZDUSD,H1)<int>: 413 ms for 100000000 iterations
2018.01.16 18:03:54.423224626_2 (NZDUSD,H1)<double>: 449 ms for 100000000 iterations
So there was also an MT5 compiler issue. :-)
P.S: My system workload was very low during these tests.
So it was finally not a compiler issue, but a memory issue. The "slow" results I had were due to disk usage (virtual memory). A bit stupid I didn't think to that sooner.
Thanks to @Fernando Carreiro for his collaboration on his instructive thread.
PS: As a side note, a computer with 4G RAM under Windows 10, is not usable without virtual memory enabled.
So it was finally not a compiler issue, but a memory issue. The "slow" results I had were due to disk usage (virtual memory). A bit stupid I didn't think to that sooner.
Thanks to @Fernando Carreiro for his collaboration on his instructive thread.
PS: As a side note, a computer with 4G RAM under Windows 10, is not usable without virtual memory enabled.
Good to know :) As for RAM, well, when I start to feel the heat, the absence of physical ram, I prefer to back off than to keep adding to it and at the same time torture my SSD. And, yes, I am on 4GB as well hehe
For those interested in efficient code and how mql4/5 code is optimized by the compiler for modern CPU/GPU, there is a very interesting discussion on Russian forum, about calculating square roots directly versus accessing an array with pre-calculated values.
OK! Here it is and I will leave it up to you to draw your own conclusions:
So I ran the scripts (1E8 iterations), once again :-D
We can easily when the script started, finished and that all 4 logical processors where used at 100%. I also checked the MT5 threads, and I confirm there was only 1 additional thread while the script was running.
Conclusion: 1 thread can used 100% of all cores. I was not aware about that.
What I couldn't understand was why the execution time is multiplied by 100 when the iterations are just multiplied by 10 (hardcoded in script, so recompiled between the 2 runs).
2018.01.16 17:54:06.223 224626_2 (NZDUSD,H1) <int>: 37 ms for 10000000 iterations
2018.01.16 17:54:06.251 224626_2 (NZDUSD,H1) <double>: 27 ms for 10000000 iterations
2018.01.16 17:59:14.606 224626_2 (NZDUSD,H1) <int>: 3545 ms for 100000000 iterations
2018.01.16 17:59:18.672 224626_2 (NZDUSD,H1) <double>: 4062 ms for 100000000 iterations
So I changed the script a bit to use an input parameter to select the iterations count, instead of it being hardcoded. And surprise :
2018.01.16 18:04:02.855 224626_2 (NZDUSD,H1) <int>: 34 ms for 10000000 iterations
2018.01.16 18:04:02.887 224626_2 (NZDUSD,H1) <double>: 31 ms for 10000000 iterations
2018.01.16 18:03:53.974 224626_2 (NZDUSD,H1) <int>: 413 ms for 100000000 iterations
2018.01.16 18:03:54.423 224626_2 (NZDUSD,H1) <double>: 449 ms for 100000000 iterations
So there was also an MT5 compiler issue. :-)
P.S: My system workload was very low during these tests.
So it was finally not a compiler issue, but a memory issue. The "slow" results I had were due to disk usage (virtual memory). A bit stupid I didn't think to that sooner.
Thanks to @Fernando Carreiro for his collaboration on his instructive thread.
PS: As a side note, a computer with 4G RAM under Windows 10, is not usable without virtual memory enabled.So it was finally not a compiler issue, but a memory issue. The "slow" results I had were due to disk usage (virtual memory). A bit stupid I didn't think to that sooner.
Thanks to @Fernando Carreiro for his collaboration on his instructive thread.
PS: As a side note, a computer with 4G RAM under Windows 10, is not usable without virtual memory enabled.Good to know :) As for RAM, well, when I start to feel the heat, the absence of physical ram, I prefer to back off than to keep adding to it and at the same time torture my SSD. And, yes, I am on 4GB as well hehe
For those interested in efficient code and how mql4/5 code is optimized by the compiler for modern CPU/GPU, there is a very interesting discussion on Russian forum, about calculating square roots directly versus accessing an array with pre-calculated values.
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Ошибки, баги, вопросы
Renat Fatkhullin, 2018.03.13 22:59
Проверка показала, что:
Вот этот код превращается в следующий ассемблерный SSE код:
Это произведение исскуства вообще-то. 8 корней вычислено за 4 вызова ассемблерной команды. Два double числа вычислялись за один вызов.
Общий вывод: математика в MQL5 побеждает за счет идеальной оптимизации. Тут не массивы проигрывают, а математика выигрывает.