Welcome, Guest
Username: Password: Remember me
Please use this forum for suggestions to the XSharp Development Team
  • Page:
  • 1

TOPIC:

Performance and VO functions Inlist and Between 18 Feb 2019 09:13 #7364

  • ArneOrtlinghaus
  • ArneOrtlinghaus's Avatar
  • Topic Author


  • Posts: 337
  • 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:

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 18 Feb 2019 09:20 #7365

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3245
  • Hello,
    I use both functions a lot, Between() much more than InList().
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 18 Feb 2019 09:28 #7368

    • robert
    • robert's Avatar


  • Posts: 3293
  • 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:
    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
    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

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 18 Feb 2019 16:30 #7378

    • Jamal
    • Jamal's Avatar


  • Posts: 303
  • I never used the InList function. I think is is so inefficient and should be deprecated.

    I prefer something like this.
    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

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 20 Feb 2019 08:48 #7391

    • MathiasHakansson
    • MathiasHakansson's Avatar


  • Posts: 50
  • What about a generic function? This is my C# version
    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;
            }
        }

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    Performance and VO functions Inlist and Between 20 Feb 2019 09:02 #7392

    • robert
    • robert's Avatar


  • Posts: 3293
  • 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

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 20 Feb 2019 09:04 #7393

    • MathiasHakansson
    • MathiasHakansson's Avatar


  • Posts: 50
  • Hmm, I could not write . After that the text is italic...

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 20 Feb 2019 09:05 #7394

    • MathiasHakansson
    • MathiasHakansson's Avatar


  • Posts: 50
  • I could not write [ i ]. Italic?

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 20 Feb 2019 10:54 #7398

    • Otto
    • Otto's Avatar


  • Posts: 174
  • if you use [ code ][ i ][/ code ] (without the spaces) you get what you want.

    [ i ]test [ /i ] gives: test
    [ code ][ i ][ /code ] gives:
    [i]

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 20 Feb 2019 11:40 #7399

    • robert
    • robert's Avatar


  • Posts: 3293
  • I have edited your message. It looks good now.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 21 Feb 2019 08:59 #7401

    • MathiasHakansson
    • MathiasHakansson's Avatar


  • Posts: 50
  • The XSharp string could override the Equals method.
    I guess usuals can have it's own equals method too. This does not solve the problem with mixed data types, but I can't remember that I ever have used Inlist with parameters of different data types. Not in VO either. I guess that does not really matter though. If it was possible in VO it should be possible in X#.

    Please Log in or Create an account to join the conversation.

    Performance and VO functions Inlist and Between 21 Feb 2019 10:26 #7403

    • robert
    • robert's Avatar


  • Posts: 3293
  • Mathias,

    There is no "XSharp String". STRING = System.String.
    So we can't override the Equals method. And also we can't inherit from System.String because that type is sealed....

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1