Not in MQL, not anymore anyways. It's actually twice as slow passing as reference in debugging, and close enough to the same when compiled normally that it really doesn't matter. Try for yourself.
#define ITERATIONS 1000000voidOnStart()
{
{
ulong time = GetMicrosecondCount();
ulong sum = 0;
for(int i=0; i<ITERATIONS; i++){
string r = string(rand());
sum += by_ref(r);
}
time = GetMicrosecondCount() - time;
printf("%s took %.3f milliseconds: sum=%dll", "by_ref", time/1000.0, sum);
}{
ulong time = GetMicrosecondCount();
ulong sum = 0;
for(int i=0; i<ITERATIONS; i++)
sum += by_val(string(rand()));
time = GetMicrosecondCount() - time;
printf("%s took %.3f milliseconds: sum=%dll", "by_val", time/1000.0, sum);
}
}
//+------------------------------------------------------------------+int by_ref(string &var){ returnint(var) % 100; }
int by_val(string var){ returnint(var) % 100; }
Also here is my final version of the working None-Type lib.
Not in MQL, not anymore anyways. It's actually twice as slow passing as reference in debugging, and close enough to the same when compiled normally that it really doesn't matter. Try for yourself.
This is most probably due to the optimiser, thats exactly typical optimising task. It recognizes the loop and does not copy the area 1 milion times, just one time and then use that area.
It might even get wiser, seeing that parm is not changed at all and not even copy once, regardless of the loop. Thats also legit optimising. Which raises issues of testing prrformances using loops, as we do many times. Just worth mentioning.
It might even get wiser, seeing that parm is not changed at all and not even copy once, regardless of the loop. Thats also legit optimising. Which raises issues of testing prrformances using loops, as we do many times. Just worth mentioning.
#define ITERATIONS 1000000voidOnStart()
{
string Str = "1";
for (int i = 0; i < 10; i++)
Str += Str;for (int j = 0; j < 5; j++)
{
{
ulong time = GetMicrosecondCount();
ulong sum = 0;
for(int i=0; i<ITERATIONS; i++){
string r = string(rand()) + Str;
sum += by_ref(r);
}
time = GetMicrosecondCount() - time;
printf("%s took %.3f milliseconds: sum=%dll", "by_ref", time/1000.0, sum);
}{
ulong time = GetMicrosecondCount();
ulong sum = 0;
for(int i=0; i<ITERATIONS; i++)
sum += by_val(string(rand()) + Str);
time = GetMicrosecondCount() - time;
printf("%s took %.3f milliseconds: sum=%dll", "by_val", time/1000.0, sum);
}
Print("");
}
}
//+------------------------------------------------------------------+int by_ref(string &var){ returnint(var) % 100; }
int by_val(string var){ returnint(var) % 100; }
by_ref took 15119.806 milliseconds: sum=-1000000ll
by_val took 13872.479 milliseconds: sum=-1000000ll
by_ref took 14433.781 milliseconds: sum=-1000000ll
by_val took 13817.533 milliseconds: sum=-1000000ll
by_ref took 13889.424 milliseconds: sum=-1000000ll
by_val took 14135.603 milliseconds: sum=-1000000ll
by_ref took 16047.643 milliseconds: sum=-1000000ll
by_val took 14494.432 milliseconds: sum=-1000000ll
by_ref took 15542.276 milliseconds: sum=-1000000ll
by_val took 13843.121 milliseconds: sum=-1000000ll
Why do you pass Value by reference? Is it to save copy time?
Yes. Especially for strings.
Yes. Especially for strings.
Not in MQL, not anymore anyways. It's actually twice as slow passing as reference in debugging, and close enough to the same when compiled normally that it really doesn't matter. Try for yourself.
Also here is my final version of the working None-Type lib.
Not in MQL, not anymore anyways. It's actually twice as slow passing as reference in debugging, and close enough to the same when compiled normally that it really doesn't matter. Try for yourself.
Interesting, thanks!
Also here is my final version of the working None-Type lib.
You missed the float FLT_MAX
Interesting, thanks!
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Ошибки, баги, вопросы
fxsaber, 2018.10.29 07:36
I am not by computer but I would try Nicholi's test with
My test: the by_val works much faster than the by_ref.