Performance and VO functions Inlist and Between

Have some feedback and input to share?
Don't be shy and drop us a note. We want to hear from you and strive to make our site better and more user friendly for our guests and members a like.
User avatar
ArneOrtlinghaus
Posts: 412
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

Performance and VO functions Inlist and Between

Post 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
Attachments
inlist.txt
(25.39 KiB) Downloaded 107 times
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Performance and VO functions Inlist and Between

Post by wriedmann »

Hello,
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
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Performance and VO functions Inlist and Between

Post 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.
XSharp Development Team
The Netherlands
robert@xsharp.eu
Jamal
Posts: 315
Joined: Mon Jul 03, 2017 7:02 pm

Performance and VO functions Inlist and Between

Post 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
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

Performance and VO functions Inlist and Between

Post 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;
        }
    }
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Performance and VO functions Inlist and Between

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

Performance and VO functions Inlist and Between

Post by MathiasHakansson »

Hmm, I could not write . After that the text is italic...
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

Performance and VO functions Inlist and Between

Post by MathiasHakansson »

I could not write [ i ]. Italic?
User avatar
Otto
Posts: 174
Joined: Wed Sep 30, 2015 6:22 pm

Performance and VO functions Inlist and Between

Post 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:

Code: Select all

[i]
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Performance and VO functions Inlist and Between

Post by robert »

I have edited your message. It looks good now.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply