Jump to content

Tom de Neef

Members
  • Content Count

    12
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by Tom de Neef


  1. And I correct the timings. As someone wrote, they vary a lot with circumstances. But the relativities are a reasonable indication.

     

    SEARCH:

    mode

    32 bit

     

    64 bit

    search

    System.pos

    NextStrPos

     

    System.pos

    NextStrPos

     

     

     

     

     

     

    String

    550

    250

     

    650

    135

    ANSIstring

    530

    460

     

    3.500

    65

     

    REPLACE:

    mode

    32 bit

     

    64 bit

    replace

    SysUtils.

    StringReplace

    StrReplace

     

    SysUtils.

    StringReplace

    StrReplace

     

     

     

     

     

     

    String

    6.500

    1.050

     

    6.000

    800

    ANSIstring

    7.400

    900

     

    7.000

    650

    • Like 2

  2. Thanks for the report - I've corrected.

     

    The functions are meant for repeated searches:

    var t : TstrPosRec; k : integer;

    begin

      t:=SetupStrPos(target,source,ignoreCase);

      repeat

         k:=NextStrPos(t);

         if k=0 then break;

         // user code, based on k

      until false;

     

    Thus the initialization overhead is outside the loop.

     

    When you code like this:

      k:=1-target.length;

      repeat

         k:=StrPos(target,source,k+target.length);

         if k=0 then break;

         // user code, based on k

      until false;

    you bring all the initialization within the loop. The StrPos function is provided only as a replacement for system.pos (and does not offer ignoreCase for that reason).

    • Like 1

  3. I have taken up two suggestions: change the license (to MIT) and use SSE4.2 (both 32 and 64 bit Windows platforms). Timing over 10M trials are as follows:

    SEARCH:

    mode

    32 bit

     

    64 bit

    search

    System.pos

    NextStrPos

     

    System.pos

    NextStrPos

     

     

     

     

     

     

    String

    550

    250

     

    730

    400

    ANSIstring

    530

    460

     

    3.500

    360

     

    REPLACE:

    mode

    32 bit

     

    64 bit

    replace

    SysUtils.

    StringReplace

    StrReplace

     

    SysUtils.

    StringReplace

    StrReplace

     

     

     

     

     

     

    String

    6.500

    1.050

     

    6.000

    1.050

    ANSIstring

    7.400

    900

     

    7.000

    850

     


  4. I've seen several queries about 64 bit equivalents for the fast string routines in Win32. And I needed them myself as well.

    I have published (assembly based) functions that mimic system.Pos and sysUtils.StringReplace for 32 & 64 bit compiling (both String and AnsiString). Extra feature: searching can be case sensitive or case insensitive.

     

    Timing for string search (1k substrings in 1M string, microsec, see documentation; NextStrPos is new):

    mode

    32 bit

     

    64 bit

    search

    System.pos

    NextStrPos

     

    System.pos

    NextStrPos

     

     

     

     

     

     

    String

    550

    500

     

    730

    400

    ANSIstring

    530

    460

     

    3.500

    360

     

    Timing for String replace (1k substrings in 1M string, microsec, see documentation; StrReplace is new):

    mode

    32 bit

     

    64 bit

    replace

    SysUtils.

    StringReplace

    StrReplace

     

    SysUtils.

    StringReplace

    StrReplace

     

     

     

     

     

     

    String

    6.500

    1.050

     

    6.000

    1.050

    ANSIstring

    7.400

    900

     

    7.000

    850

     

    Files and documentation on https://sourceforge.net/projects/delphi-fast-pos-stringreplace/

    • Like 3

  5. (This is a re-start of another thread)

    I have published Delphi sorting routines that ought to be similar in speed to TIMsort, for arrays of simple types, strings and objects.

    The focus has been on large (10M+) real-world situations, where there is already some order in the data.

    The documentation explains how to use in case you do not want generics.

    The software is free: https://sourceforge.net/projects/fast-stable-sorting-in-delphi/   It includes a test suite.

    Stable sorting of objects with QuickSort is possible by adding to the object a tag that can serve as stability key. In that way I compare sorting speeds of my procedures with Tarray.sort<Tobject>. For (semi-)random data the difference is 5-10 times. When there is already order in the data, the improvement may go up to a factor of 20.

    I chose some optimization parameters on the basis of the test arrays that I generated. It would be nice to know if attractive results are obtained when applied to real-world data.

    • Like 2
    • Thanks 1

  6. You have a point. But we're talking here about arrays with millions of elements. Who cares about speed when the array is just a few thousand elements long?

    My interest comes from server code where the data involves 5 million records and where, together with all the other processing, the target response time is 300 msec.

    Anyway, I hope that my contribution to the community is of some value.


  7. Sorting a reversed sorted array is more from the academic world than from the real world. But I have taken the hint and modified the code so that reversed input will be treated well. 

    For real-world data (like sorted arrays that have been modified and need re-sorting) and for stable sorting of objects, the speed gain over Delphi's default sorting is immense. It would be nice to see some practical tests.


  8. I have just published Delphi sorting routines that ought to be similar in speed to TIMsort, for arrays of simple types, strings and objects.

    The focus has been on large (10M+) real-world situations, where there is already some order in the data.

    The documentation explains how to use in case you do not want generics.

    The software is free: https://sourceforge.net/projects/fast-stable-sorting-in-delphi/

    Hope it is of use.

    • Like 1
    • Thanks 1
×