Performance and VO functions Inlist and Between
- ArneOrtlinghaus
- Posts: 413
- Joined: Tue Nov 10, 2015 7:48 am
- Location: Italy
Performance and VO functions Inlist and Between
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
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
- Attachments
-
- inlist.txt
- (25.39 KiB) Downloaded 113 times
Performance and VO functions Inlist and Between
Hello,
I use both functions a lot, Between() much more than InList().
Wolfgang
I use both functions a lot, Between() much more than InList().
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Performance and VO functions Inlist and Between
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:
and then in the function InList something like
etc.
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
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)
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Performance and VO functions Inlist and Between
I never used the InList function. I think is is so inefficient and should be deprecated.
I prefer something like this.
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
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Performance and VO functions Inlist and Between
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
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
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
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Performance and VO functions Inlist and Between
Hmm, I could not write . After that the text is italic...
-
- Posts: 50
- Joined: Fri Feb 16, 2018 7:52 am
Performance and VO functions Inlist and Between
I could not write [ i ]. Italic?
Performance and VO functions Inlist and Between
if you use [ code ][ i ][/ code ] (without the spaces) you get what you want.
[ i ]test [ /i ] gives: test
[ code ][ i ][ /code ] gives:
[ i ]test [ /i ] gives: test
[ code ][ i ][ /code ] gives:
Code: Select all
[i]
Performance and VO functions Inlist and Between
I have edited your message. It looks good now.
Robert
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu