Which is faster - Floating-Point or Integer arithmetic? - page 11

 
Alain Verleyen: I just ran the script. I know the results are "weird" and that's well why we got these big misunderstanding yesterday. I suppose it depends on the workload of the CPU/GPU (yesterday morning it was 8 times slower for double, now it's 2 times (1E8), while 1E7 iterations give similar results). 

Could MT5 be using parallel "multi-threading" approach to certain calculations of which we are unaware?

As @whroeder1 pointed out about the FPU/CPU situations (which completely makes sense), and so calculations could be "spread out" somehow, and the workload of the machine could cause very drastic changes to that environment and affect the results in the "weird" way!

EDIT: What other computational intensive software are you using on your PC? Could there be maybe some heavy floating point math taking place that is stealing "FPU" cycles away from MetaTrader and thus giving the Integer side an advantage?

 
Fernando Carreiro:

Sorry, but I don't feel the need to "prove" it by showing my EA code implementations! All that is important for this thread is that it has been shown that the assumptions (mine included) about the faster Integer advantage are no longer a given, and that in many cases Floating-point is actually faster.

So I guess I went from a 6 year old who deserves to be banned to paradigm changer, huh? Lol. Why do you guys always have to be so difficult? 
 
Fernando Carreiro:

Could MT5 be using parallel "multi-threading" approach to certain calculations of which we are unaware?

Probably not, at least what is documented is 1 thread by EA/Script. But who knows ?

As @whroeder1 pointed out about the FPU/CPU situations (which completely makes sense), and so calculations could be "spread out" somehow, and the workload of the machine could cause very drastic changes to that environment and affect the results in the "weird" way!

EDIT: What other computational intensive software are you using on your PC? Could there be maybe some heavy floating point math taking place that is stealing "FPU" cycles away from MetaTrader and thus giving the Integer side an advantage?

Currently not much I think (Chrome a lot of open tabs, MT4/MT5 one instance each, Excel, Skype, Thunderbird). Later I could test with all other applications closed. Also running the script on several charts simultaneously, etc...

 
nicholishen: So I guess I went from a 6 year old who deserves to be banned to paradigm changer, huh? Lol. Why do you guys always have to be so difficult? 

The double to int conversion, is no longer part of this thread and that is the reason why I requested the split. This thread is now dedicated to the sole purpose of analysing the speed issues with regards to Integer and Floating point arithmetic.

How I implement the conversion overhead compensation is not relevant here, and pardon me if I do not wish to describe my code implementations with you or anyone else. It is my prerogative to keep my EA code to myself if I so wish it.

I'm not trying to convince you about it either, so you are free to believe or think what ever you want on that matter!

We also agreed that we would start fresh and hold back on all hostilities and keep things civil, so please adhere to that!

 
Alain Verleyen: Probably not, at least what is documented is 1 thread by EA/Script. But who knows ? Currently not much I think (Chrome a lot of open tabs, MT4/MT5 one instance each, Excel, Skype, Thunderbird). Later I could test with all other applications closed. Also running the script on several charts simultaneously, etc...

It that case, I may be actually be using more FPU intensive applications than you because sometimes I do have MathCAD and Photoshop open at the same time as MetaTrader.

So, I closed everything down and did the test again, but I still get similar results as before! Could it be that maybe your CPU and FPU is implemented differently for your ChipSet?

I'm not really to well informed these days about CPU/FPU/GPU internals, so don't really know if it is a factor or not.

Unfortunately, @whroeder1 has still not answered and I suspect he will not, so we are left to our own devices in order to study this.

 
Fernando Carreiro:

It that case, I may be actually be using more FPU intensive applications than you because sometimes I do have MathCAD and Photoshop open at the same time as MetaTrader.

So, I closed everything down and did the test again, but I still get similar results as before! Could it be that maybe your CPU and FPU is implemented differently for your ChipSet?

I suppose yes.

I'm not really to well informed these days about CPU/FPU/GPU internals, so don't really know if it is a factor or not.

Unfortunately, @whroeder1 has still not answered and I suspect he will not, so we are left to our own devices in order to study this.

We will try to figure it out.

EDIT: did you already try on an older computer ?
 
Alain Verleyen:

I suppose yes.

We will try to figure it out.

EDIT: did you already try on an older computer ?
Yes, but only for MT4. I will install MT5 on it now and give you some feedback in 10-15 mins on the results!
 
Alain Verleyen: did you already try on an older computer ?

OK, so here are the results on an older PC:

2018.01.16 15:50:01.880    Terminal    MetaTrader 5 - RoboForex x64 build 1745 started (RoboTrade Ltd.)
2018.01.16 15:50:01.895    Terminal    Windows Server 2008 R2 Service Pack 1 (build 7601) x64, IE 11, RDP, UAC, Intel Core2 Quad  Q6600 @ 2.40GHz, Memory: 4318 / 8174 Mb, Disk: 206 / 1862 Gb, GMT+0

2018.01.16 15:50:18.239    224626_2 (EURUSD.m,H1)    <int>: 61 ms for 10000000 iterations
2018.01.16 15:50:18.255    224626_2 (EURUSD.m,H1)    result = 9981310 sum=327712782746
2018.01.16 15:50:18.286    224626_2 (EURUSD.m,H1)    <double>: 44 ms for 10000000 iterations
2018.01.16 15:50:18.286    224626_2 (EURUSD.m,H1)    result = 9981310 sum=327712782746.000000

2018.01.16 15:50:44.145    224626_2 (EURUSD.m,H1)    <int>: 590 ms for 100000000 iterations
2018.01.16 15:50:44.145    224626_2 (EURUSD.m,H1)    result = 99813267 sum=3276873120549
2018.01.16 15:50:44.630    224626_2 (EURUSD.m,H1)    <double>: 491 ms for 100000000 iterations
2018.01.16 15:50:44.630    224626_2 (EURUSD.m,H1)    result = 99813267 sum=3276873120549.000000

This is a Server machine that is running multiple services such as my home's multimedia sharing, file services, FTP server, as well as two bittorrent clients.

Please note however, that these are desktop machines and none of them are using Mobile versions of CPUs like your case (which could be an important point).

EDIT: Unfortunately, I no longer have a laptop to test on (as it broke down) and I have not replaced it yet!

 
Alain Verleyen: I suppose yes.

I see from the specs that your CPU only has 2 cores, and both the machines I used for the test have 4 cores, instead of 2.

I will now test on the VPS with only one core and see what happens!

 
Alain Verleyen: did you already try on an older computer ?

Good news, as I was able to replicate your results on the VPS with only a single core:


2018.01.16 18:54:18.642    Terminal    MetaTrader 5 - RoboForex x64 build 1745 started (RoboTrade Ltd.)
2018.01.16 18:54:18.642    Terminal    Windows Server 2008 R2 Service Pack 1 (build 7601) on KVM x64, IE 11, RDP, UAC, Virtual  a7769a6388d5, Memory: 787 / 1023 Mb, Disk: 5 / 24 Gb, GMT+2

2018.01.16 18:55:26.487    224626_2 (EURUSD.m,H1)    <int>: 4534 ms for 50000000 iterations
2018.01.16 18:55:26.502    224626_2 (EURUSD.m,H1)    result = 49906989 sum=1638461408474
2018.01.16 18:55:45.051    224626_2 (EURUSD.m,H1)    <double>: 18548 ms for 50000000 iterations
2018.01.16 18:55:45.066    224626_2 (EURUSD.m,H1)    result = 49906989 sum=1638461408474.000000


2018.01.16 18:57:51.380    224626_2 (EURUSD.m,H1)    <int>: 40 ms for 10000000 iterations
2018.01.16 18:57:51.380    224626_2 (EURUSD.m,H1)    result = 9981514 sum=327585184842
2018.01.16 18:57:51.442    224626_2 (EURUSD.m,H1)    <double>: 59 ms for 10000000 iterations
2018.01.16 18:57:51.442    224626_2 (EURUSD.m,H1)    result = 9981514 sum=327585184842.000000

2018.01.16 18:57:35.140    224626_2 (EURUSD.m,H1)    <int>: 17 ms for 5000000 iterations
2018.01.16 18:57:35.140    224626_2 (EURUSD.m,H1)    result = 4990589 sum=163877961134
2018.01.16 18:57:35.156    224626_2 (EURUSD.m,H1)    <double>: 13 ms for 5000000 iterations
2018.01.16 18:57:35.156    224626_2 (EURUSD.m,H1)    result = 4990589 sum=163877961134.000000


I was not able to run the full 1E8 iterations (but instead ran half that), because I did not dimension enough RAM for the VPS when I set it up.

However, the test did solve the "weird" riddle, as now we know that the number of cores severely affects the results. For 2 cores or less, it seems that Integer arithmetic is much faster, but on a 4 core the floating point is faster (but not by much). The number of cores alone may not be the true reason, but maybe another factor is the cause, but it is an indication of the "weird" results.

So, for those running EAs on VPS's that use less resources (cores) to save on the cost of a VPS, Integer arithmetic can offer an advantage! On 4 cores the floating point is faster but not by a great deal, so if considering a general approach, Integer arithmetic may still be advisable, depending on other factors such as the conversion overhead.

Users will have to test their EA implementations on a case-by-case method and see which is faster for them.

On a whole, the "old paradigm" may not be dead just yet, although it seems that it may be dying out as technology progresses! I will have to do more research and educate myself more on this subject!

EDIT: This also poses the question of whether EAs do in fact run on a single thread as documented or if there is in fact some multi-threaded functionality involved. It may in fact be happening at the hardware level, but unfortunately I don't have enough knowledge or experience with current CPU/FPU implementations to be able to comment on this!

EDIT2: It has come to my attention that these tests should also be carried out on AMD processors and that the results could be quite different too.

Reason: