Page 1 of 2
Performance and VO functions Inlist and Between
Posted: Mon Feb 18, 2019 8:13 am
by ArneOrtlinghaus
The X#-Runtime has made great progresses what is regarding the performance!
I am already in the phase of optimizing details.
With the time profile I found two functions that may slowdown execution when used often: The Inlist and the between functions.
I like these two functions very much, they simplify code expressions.
I have written strong typed substitutions for these functions as in the attachment to have a simple tools for enhancing the old code. For example an Inlist in the dispatch method of a window is visible in the profiler. It was worth doing this and it was not so much work: it was not necessary to test each code change, because the compiler said if something was wrong.
May be in the future the X# developers can find a way to internally substitute these functions, I don't know how many programmers have used these functions extensively.
Arne
Performance and VO functions Inlist and Between
Posted: Mon Feb 18, 2019 8:20 am
by wriedmann
Hello,
I use both functions a lot, Between() much more than InList().
Wolfgang
Performance and VO functions Inlist and Between
Posted: Mon Feb 18, 2019 8:28 am
by robert
Arne,
We can and will certainly optimize these functions in a future version of the runtime.
Most likely we will not create a dozen or so overloads for the string or numeric variations. I am thinking of something like:
Code: Select all
FUNCTION InListString( sToSearchFor as STRING, sPossibleMatches PARAMS STRING[])
FOREACH VAR sMatch in sPossibleMatches
IF sToSearchFor == sMatch
RETURN TRUE
ENDIF
NEXT
and then in the function InList something like
Code: Select all
FUNCTION InList(u, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
IF IsString(u)
SWITCH PCount()
CASE 16 // u + 15 comparisons
RETURN InListString( u, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
CASE 15
RETURN InListString( u, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)
etc.
Performance and VO functions Inlist and Between
Posted: Mon Feb 18, 2019 3:30 pm
by Jamal
I never used the InList function. I think is is so inefficient and should be deprecated.
I prefer something like this.
Code: Select all
FUNCTION InArray(sToSearchFor AS STRINGr, aArrayItems AS ARRAY) AS LOGIC
LOCAL litemsCount as LONG
LOCAL lFound as LOGIC
For i := 1 UPTO litemsCount
IF sToSearchFor == aArrayItems[I]
lFound := TRUE
EXIT
ENDIF
NEXT
RETURN lFound
Performance and VO functions Inlist and Between
Posted: Wed Feb 20, 2019 7:48 am
by MathiasHakansson
What about a generic function? This is my C# version
Code: Select all
public static class ArrayHelper
{
public static bool InList<T>(params T[] paramArray)
{
if (paramArray.Length < 2)
return false;
T first = paramArray[0];
for (int i = 1; i < paramArray.Length; i++)
if (first.Equals(paramArray[i]))
return true;
return false;
}
}
Performance and VO functions Inlist and Between
Posted: Wed Feb 20, 2019 8:02 am
by robert
Mathias,
In general yes, this is a good solution.
However for string fields we can't use the normal Equals operator because we also have to take into account the SetExact setting.
And VO is also very "optimistic". You can have both integer and float values in the list and VO will happily process both, because it will do a USUAL comparison between the values.
Robert
Performance and VO functions Inlist and Between
Posted: Wed Feb 20, 2019 8:04 am
by MathiasHakansson
Hmm, I could not write . After that the text is italic...
Performance and VO functions Inlist and Between
Posted: Wed Feb 20, 2019 8:05 am
by MathiasHakansson
I could not write [ i ]. Italic?
Performance and VO functions Inlist and Between
Posted: Wed Feb 20, 2019 9:54 am
by Otto
if you use [ code ][ i ][/ code ] (without the spaces) you get what you want.
[ i ]test [ /i ] gives:
test
[ code ][ i ][ /code ] gives:
Performance and VO functions Inlist and Between
Posted: Wed Feb 20, 2019 10:40 am
by robert
I have edited your message. It looks good now.
Robert