Home AMX User Forum AMX General Discussion

Which is faster vs proper

2»

Comments

  • viningvining Posts: 4,368
    Well I ran some more tests and tried them on both an NI3100 and NX2200 and I'm a little dumb founded.
    NI
    Line      2 (20:43:21)::  String table test "ReplaceChars"                completed 200 loops in 209 milliseconds.
    Line      3 (20:43:21)::  String table test "StringReplace"               completed 200 loops in 101 milliseconds.
    Line      4 (20:43:21)::  String table test "TrimCharsFromHead"           completed 200 loops in 30 milliseconds.
    Line      5 (20:43:21)::  String table test "TrimCharsFromTail"           completed 200 loops in 29 milliseconds.
    Line      6 (20:43:22)::  String table test "fnTrimCharsFromHead___"      completed 200 loops in 153 milliseconds.
    Line      7 (20:43:22)::  String table test "fnTrimCharsFromHead_xx"      completed 200 loops in 283 milliseconds.
    Line      8 (20:43:22)::  String table test fnTrimCharsFromHeadxv         completed 200 loops in 250 milliseconds.
    Line      9 (20:43:22)::  String table test "TrimCharsFromString"         completed 200 loops in 293 milliseconds.
    
    
    NX
    Line     11 (20:49:10)::  String table test "ReplaceChars"                completed 200 loops in 325 milliseconds.
    Line     12 (20:49:10)::  String table test "StringReplace"               completed 200 loops in 96 milliseconds.
    Line     13 (20:49:10)::  String table test "TrimCharsFromHead"           completed 200 loops in 41 milliseconds.
    Line     14 (20:49:10)::  String table test "TrimCharsFromTail"           completed 200 loops in 44 milliseconds.
    Line     15 (20:49:10)::  String table test "fnTrimCharsFromHead___"      completed 200 loops in 152 milliseconds.
    Line     16 (20:49:11)::  String table test "fnTrimCharsFromHead_xx"      completed 200 loops in 114 milliseconds.
    Line     17 (20:49:11)::  String table test fnTrimCharsFromHeadxv         completed 200 loops in 97 milliseconds.
    Line     18 (20:49:11)::  String table test "TrimCharsFromString"         completed 200 loops in 388 milliseconds.
    

    The ReplaceChars function is the one posted earlier and the StringReplace is this one below, the ReplaceChars function just swaps a single char but you can put multiple swaps in the table whereas the StringReplace will do entire string if needed so in the test I just did a single char to replace in the same position of the same string and the table version got smoked in both the NI and NX. The TrimCharsFromString uses a table and is extremely slow in both masters and the TrimCharsFromHead functions with the crap appended are just variants that don't use the table method. There's something odd going on that needs more investigating cuz I was expecting all table function to do great in the NX and they clearly don't which makes no sense and likewise in early test functions using find_string were fast in the NI's but slow in the NX but here the StringReplace which uses one was faster in the NX all be it by a small amount. Some table function were actually faster in the NI this time. This is very strange..........................
    DEFINE_FUNCTION CHAR[2000] fnStrReplace(CHAR strSTR[], CHAR strSEARCH[], CHAR strREPLACE[])
         
         {
         STACK_VAR INTEGER nPOS
         STACK_VAR CHAR strTRASH[2000]
         STACK_VAR CHAR strTEMP_STR[2000]
    
         nPOS = FIND_STRING(strSTR, "strSEARCH", 1)
         IF (!nPOS)
          RETURN strSTR;
         WHILE (nPOS)
          {
          strTEMP_STR = ""
          IF (nPOS > 1)
               strTEMP_STR = LEFT_STRING(strSTR, nPOS - 1)
          strTRASH = REMOVE_STRING(strSTR, "strTEMP_STR, strSEARCH", 1)
          strSTR = "strTEMP_STR, strREPLACE, strSTR"
          nPOS = FIND_STRING(strSTR, "strSEARCH", nPOS + LENGTH_STRING(strREPLACE))
          }
         RETURN strSTR;
         }          
    
Sign In or Register to comment.