Is <11 faster than <=10? - page 4

To add comments, please log in or register
nadiawicket
945
nadiawicket  
Ilyas:

What do you know about constant expressions?

Of course both of them was caclulated on compile time

Print(GetMicrosecondCount(),true,GetMicrosecondCount());

takes the same time as

Print(GetMicrosecondCount(),10<11,GetMicrosecondCount());

bc all constant expressions get processed the same by compiler no matter how many comparisons inside the constant expression or how complex

Seng Joo Thio
1155
Seng Joo Thio  
Ilyas:

Try to run this code in the MT5 (64 bit version)

Ha! Apparently MQL5 compiler is smarter than MQL4. So I've modified my test code to this for MT5:

ulong iStart = 0, iStop = 0;
bool bResult;

void OnStart()
  {
   MathSrand(1);
   
   for (int i=0; i<100; i++)
   {
      int T1 = TestL(), T2 = TestLT();
      PrintFormat("Run %3d:    (<) %8d      (<=) %8d     (Diff) %8d", i, T1, T2, T1-T2);
   }
  }

int TestL()
{
   iStart = GetMicrosecondCount();
   for (int i=0; i<INT_MAX; i++)
      bResult = MathRand()<MathRand();
   iStop = GetMicrosecondCount();
   return int(iStop-iStart);
}

int TestLT()
{
   iStart = GetMicrosecondCount();
   for (int i=0; i<INT_MAX; i++)
      bResult = MathRand()<=MathRand();
   iStop = GetMicrosecondCount();
   return int(iStop-iStart);
}

And got these results:

2019.09.13 10:43:09.576 TimeCompare (EURUSD,H1) Run   0:    (<)  3251195      (<=)  3258806     (Diff)    -7611
2019.09.13 10:43:16.085 TimeCompare (EURUSD,H1) Run   1:    (<)  3256095      (<=)  3253379     (Diff)     2716
2019.09.13 10:43:22.601 TimeCompare (EURUSD,H1) Run   2:    (<)  3253561      (<=)  3262695     (Diff)    -9134
2019.09.13 10:43:29.155 TimeCompare (EURUSD,H1) Run   3:    (<)  3265525      (<=)  3288037     (Diff)   -22512
2019.09.13 10:43:35.712 TimeCompare (EURUSD,H1) Run   4:    (<)  3279700      (<=)  3277488     (Diff)     2212
2019.09.13 10:43:42.232 TimeCompare (EURUSD,H1) Run   5:    (<)  3265474      (<=)  3254666     (Diff)    10808
2019.09.13 10:43:48.749 TimeCompare (EURUSD,H1) Run   6:    (<)  3251214      (<=)  3265092     (Diff)   -13878
2019.09.13 10:43:55.451 TimeCompare (EURUSD,H1) Run   7:    (<)  3327507      (<=)  3374782     (Diff)   -47275
2019.09.13 10:44:02.033 TimeCompare (EURUSD,H1) Run   8:    (<)  3300733      (<=)  3281478     (Diff)    19255
2019.09.13 10:44:08.619 TimeCompare (EURUSD,H1) Run   9:    (<)  3296160      (<=)  3289838     (Diff)     6322
2019.09.13 10:44:15.195 TimeCompare (EURUSD,H1) Run  10:    (<)  3303194      (<=)  3272786     (Diff)    30408
2019.09.13 10:44:21.744 TimeCompare (EURUSD,H1) Run  11:    (<)  3263333      (<=)  3285502     (Diff)   -22169
2019.09.13 10:44:28.286 TimeCompare (EURUSD,H1) Run  12:    (<)  3279565      (<=)  3262725     (Diff)    16840
2019.09.13 10:44:34.851 TimeCompare (EURUSD,H1) Run  13:    (<)  3262456      (<=)  3301616     (Diff)   -39160
2019.09.13 10:44:41.401 TimeCompare (EURUSD,H1) Run  14:    (<)  3275717      (<=)  3274250     (Diff)     1467
2019.09.13 10:44:47.965 TimeCompare (EURUSD,H1) Run  15:    (<)  3268762      (<=)  3296008     (Diff)   -27246
2019.09.13 10:44:54.527 TimeCompare (EURUSD,H1) Run  16:    (<)  3285400      (<=)  3276538     (Diff)     8862
2019.09.13 10:45:01.064 TimeCompare (EURUSD,H1) Run  17:    (<)  3274269      (<=)  3262228     (Diff)    12041
2019.09.13 10:45:07.631 TimeCompare (EURUSD,H1) Run  18:    (<)  3272255      (<=)  3294545     (Diff)   -22290
2019.09.13 10:45:14.163 TimeCompare (EURUSD,H1) Run  19:    (<)  3263302      (<=)  3269002     (Diff)    -5700
2019.09.13 10:45:20.703 TimeCompare (EURUSD,H1) Run  20:    (<)  3275299      (<=)  3264344     (Diff)    10955
2019.09.13 10:45:27.285 TimeCompare (EURUSD,H1) Run  21:    (<)  3282645      (<=)  3299276     (Diff)   -16631
2019.09.13 10:45:33.864 TimeCompare (EURUSD,H1) Run  22:    (<)  3292700      (<=)  3286853     (Diff)     5847
2019.09.13 10:45:40.533 TimeCompare (EURUSD,H1) Run  23:    (<)  3359401      (<=)  3309287     (Diff)    50114
2019.09.13 10:45:47.114 TimeCompare (EURUSD,H1) Run  24:    (<)  3277958      (<=)  3302485     (Diff)   -24527
2019.09.13 10:45:53.641 TimeCompare (EURUSD,H1) Run  25:    (<)  3273937      (<=)  3253639     (Diff)    20298

So, as before, there is no clear winner. Time fluctuations, given their magnitude of <100 milliseconds for 2147483647 operations (inclusive of 2 x MathRand on top of < or <=), are likely due to pc load.

nadiawicket
945
nadiawicket  
Seng Joo Thio:

Ha! Apparently MQL5 compiler is smarter than MQL4. So I've modified my test code to this for MT5:

And got these results:

So, as before, there is no clear winner. Time fluctuations, given their magnitude of <100 milliseconds for 2147483647 operations (inclusive of 2 x MathRand on top of < or <=), are likely due to pc load.

awesome info!!

and also everyone else who posted

Mike Tanton
535
Mike Tanton  

If I can add my 2 cents here... I also was eternally worried about code and processing speed... but... the bottom line is this:

Electricity travels at just under the speed of light... light speeds around the Earth at I think 7.5 revolutions per second...

So, yes... there is possibly a difference in speed...

But is it negligible.....

Pimpinela
119
Pimpinela  
100000000000 iterations of <11 take 3 minutes 55 secs.
100000000000 iterations of <=10 take 3 minutes 54 secs.

So the winner is <=10 even if I believe its a tie.
Drazen Penic
2940
Drazen Penic  
Pimpinela:
100000000000 iterations of <11 take 3 minutes 55 secs.
100000000000 iterations of <=10 take 3 minutes 54 secs.

So the winner is <=10 even if I believe its a tie.

Nitpicking:

Are you 100% sure that there were no other system processes running in the background while you were running "<" test?

For example: did windows update run? antivirus regular check? Chrome browser update check? Chat apps received messages with images and/or videos? Maybe MT4 downloaded new version in background? Any other windows process that could use processor time?

In short: can you claim that both tests had EXACTLY the same computing environment?

Amir Yacoby
1373
Amir Yacoby  
Why do you guys still bothered about this non relevant non-issue which was already resolved by official metaquotes answer (that they are exactly the same in MT5 and MT5) ?

Are you bored?

Why don't you check if A=A+ 3 is faster or slower than A=A+13 for instance? If you check for 100 milion runs, it will show a small difference as well.

It's exactly the same, no matter what your 'tests' show.

And it will not make any slightest difference in making a better ea, why don't you accept metaquotes answer..  It's just a false question, false problem. Nothing, not worth any more reference.
Amir Yacoby
1373
Amir Yacoby  
Drazen Penic:

Nitpicking:

Are you 100% sure that there were no other system processes running in the background while you were running "<" test?

For example: did windows update run? antivirus regular check? Chrome browser update check? Chat apps received messages with images and/or videos? Maybe MT4 downloaded new version in background? Any other windows process that could use processor time?

In short: can you claim that both tests had EXACTLY the same computing environment?

Of course its just a pc load issue.

Alain Verleyen
38895
Alain Verleyen  
Amir Yacoby:
Why do you guys still bothered about this non relevant non-issue which was already resolved by official metaquotes answer (that they are exactly the same in MT5 and MT5) ?

Are you bored?

Why don't you check if A=A+ 3 is faster or slower than A=A+13 for instance? If you check for 100 milion runs, it will show a small difference as well.

It's exactly the same, no matter what your 'tests' show.

And it will not make any slightest difference in making a better ea, why don't you accept metaquotes answer..  It's just a false question, false problem. Nothing, not worth any more reference.
That's funny to see how some topics which deserve like 4 posts maximum, go to 40.
William Roeder
19663
William Roeder  
#40 Maximum of 4? I answered OP in #1. :)
To add comments, please log in or register