Amir Yacoby: Can you try by ref with const in by_ref?
#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++){
conststring 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(conststring &var){ returnint(var) % 100; }
int by_val(conststring var){ returnint(var) % 100; }
by_ref took 15315.273 milliseconds: sum=-1000000ll
by_val took 16784.371 milliseconds: sum=-1000000ll
by_ref took 16005.445 milliseconds: sum=-1000000ll
by_val took 16408.359 milliseconds: sum=-1000000ll
by_ref took 14450.029 milliseconds: sum=-1000000ll
by_val took 15010.212 milliseconds: sum=-1000000ll
by_ref took 15458.176 milliseconds: sum=-1000000ll
by_val took 17585.525 milliseconds: sum=-1000000ll
by_ref took 16557.555 milliseconds: sum=-1000000ll
by_val took 15207.455 milliseconds: sum=-1000000ll
Amir Yacoby: In the case of using IsNone the defines become redundant - which I think it's much better because it enforces to use only the functions alone
Yes, the only time you needto use the NONE/IS_NONE macros is when working with templates. Otherwise it is more efficient to use constants and expressions.
Yes, the only time you needto use the NONE/IS_NONE macros is when working with templates. Otherwise it is more efficient to use constants and expressions.
That's correct. Btw, there's another interesting use for this lib that crossed my mind. You can pass to functions/methods any combination of parameters with default values (not restricted to the end of parameters list)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
My test: the by_val works much faster than the by_ref.
Can you try by ref with const in by_ref?
My test: the by_val works much faster than the by_ref.
Same here, which is why I don't use refs unless I need them.... It's not even about the speed it just makes passing args a pain in the !@#.
You missed the float FLT_MAX
You're absolutely right! Thanks!
I forgot it was even a type in MQL... 😜 Honestly though, I don't recall ever actually seeing it used in an MQL program.
Passing by reference copies the reference to the stack - and adds some more indirect stuff.
Same here, which is why I don't use refs unless I need them.... It's not even about the speed it just makes passing args a pain in the !@#.
You're absolutely right! Thanks!
I forgot it was even a type in MQL... 😜 Honestly though, I don't recall ever actually seeing it used in an MQL program.
Why btw you choose not to use the IsNone(type) methods by fxsaber?
Great idea!
BTW, thanks fxsaber!
#define NONE_DOUBLE DBL_MAX
#define NONE_FLOAT FLT_MAX
#define NONE_INT INT_MAX
#define NONE_UINT UINT_MAX
#define NONE_LONG LONG_MAX
#define NONE_ULONG ULONG_MAX
#define NONE_CHAR CHAR_MAX
#define NONE_UCHAR UCHAR_MAX
#define NONE_SHORT SHORT_MAX
#define NONE_USHORT USHORT_MAX
#define NONE_COLOR clrNONE
#define NONE_DATETIME -1
#define NONE_POINTER NULL
#define NONE_STRING "__NONE-*-*-STRING__"
In the case of using IsNone the defines become redundant - which I think it's much better because it enforces to use only the functions alone
#define NONE_DOUBLE DBL_MAX
#define NONE_FLOAT FLT_MAX
#define NONE_INT INT_MAX
#define NONE_UINT UINT_MAX
#define NONE_LONG LONG_MAX
#define NONE_ULONG ULONG_MAX
#define NONE_CHAR CHAR_MAX
#define NONE_UCHAR UCHAR_MAX
#define NONE_SHORT SHORT_MAX
#define NONE_USHORT USHORT_MAX
#define NONE_COLOR clrNONE
#define NONE_DATETIME -1
#define NONE_POINTER NULL
#define NONE_STRING "__NONE-*-*-STRING__"
Yes, the only time you need to use the NONE/IS_NONE macros is when working with templates. Otherwise it is more efficient to use constants and expressions.
Yes, the only time you need to use the NONE/IS_NONE macros is when working with templates. Otherwise it is more efficient to use constants and expressions.
Btw, there's another interesting use for this lib that crossed my mind.
You can pass to functions/methods any combination of parameters with default values (not restricted to the end of parameters list)
*-in that case it is better to give the default positive value in the function method itself (for parm2=5.1):
Which allows to call without the caller knowing the actual default value of the 2nd parameter.