Results 1 to 1 of 1

Thread: Fast string handling in thinBasic 1.10.5

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Fast string handling in thinBasic 1.10.5

    thinBasic 1.10.5 introduced some new FAST version of standard string functions that ... are in some cases thousands of times faster than they standard counterpart
    FAST function versions are like standard one but with an F in the name. Example: MIDF$, LEFTF$, RIGHTF$, LENF, GRABF$, PARSEF$, PARSECOUNTF
    The bigger the string, the better will be results.

    Below example show their usage and results on my PC are the following:
    Size of string: 11,000,000 bytes

    Time to perform 100 mid$: 0.941708
    Time to perform 100 midF$: 0.000136
    6924.324x faster

    Time to perform 100 left$: 0.916229
    Time to perform 100 leftF$: 0.000154
    5949.539x faster

    Time to perform 100 right$: 0.906004
    Time to perform 100 rightF$: 0.000173
    5237.017x faster

    Time to perform 100 len$: 1.841468
    Time to perform 100 lenF$: 0.000065
    28330.277x faster

    Time to perform 100 parse$: 0.849208
    Time to perform 100 parseF$: 0.000356
    2385.416x faster

    Time to perform 100 grab$: 0.863512
    Time to perform 100 grabF$: 0.000425
    2031.793x faster



    Example
    #MinVersion 1.10.5
    
    
    uses "console"
    
    
    ext delta, deltaF
    string buffer
    buffer = repeat$(1000000, "(BCDEFGHI),")
    
    
    printl "Size of string: " + format$(len(buffer), "#,") + " bytes"
    printl
    
    
    string x
    long length
    
    
    long n
    
    
    hirestimer_init
    
    
    ' ---- ---- ---- ---- ---- ----
    
    
    hirestimer_get
    for n = 1 to 100
      x = Mid$(buffer, 1000, 10)
    Next
    delta = hirestimer_delta/1000000
    PrintL "Time to perform 100 mid$: ", format$(delta, "#0.000000")
    
    
    hirestimer_get
    for n = 1 to 100
      x = MidF$(buffer, 1000, 10)
    Next
    deltaF = hirestimer_delta/1000000
    PrintL "Time to perform 100 midF$:", format$(deltaF, "#0.000000")
    PrintL format$(delta/deltaF, "#.000") + "x faster"
    PrintL
    ' ---- ---- ---- ---- ---- ----
    
    
    hirestimer_get
    for n = 1 to 100
      x = left$(buffer, 1000)
    Next
    delta = hirestimer_delta/1000000
    PrintL "Time to perform 100 left$: ", format$(delta, "#0.000000")
    
    
    hirestimer_get
    for n = 1 to 100
      x = leftF$(buffer, 1000)
    Next
    deltaF = hirestimer_delta/1000000
    PrintL "Time to perform 100 leftF$:", format$(deltaF, "#0.000000")
    PrintL format$(delta/deltaF, "#.000") + "x faster"
    PrintL
    ' ---- ---- ---- ---- ---- ----
    
    
    hirestimer_get
    for n = 1 to 100
      x = right$(buffer, 1000)
    Next
    delta = hirestimer_delta/1000000
    PrintL "Time to perform 100 right$: ", format$(delta, "#0.000000")
    
    
    hirestimer_get
    for n = 1 to 100
      x = rightF$(buffer, 1000)
    Next
    deltaF = hirestimer_delta/1000000
    PrintL "Time to perform 100 rightF$:", format$(deltaF, "#0.000000")
    PrintL format$(delta/deltaF, "#.000") + "x faster"
    PrintL
    ' ---- ---- ---- ---- ---- ----
    
    
    hirestimer_get
    for n = 1 to 100
      length = len(buffer)
    Next
    delta = hirestimer_delta/1000000
    PrintL "Time to perform 100 len$: ", format$(delta, "#0.000000")
    
    
    hirestimer_get
    for n = 1 to 100
      length = lenf(buffer)
    Next
    deltaF = hirestimer_delta/1000000
    PrintL "Time to perform 100 lenF$:", format$(deltaF, "#0.000000")
    PrintL format$(delta/deltaF, "#.000") + "x faster"
    PrintL
    ' ---- ---- ---- ---- ---- ----
    
    
    hirestimer_get
    for n = 1 to 100
      x = parse$(buffer, ",", n)
    Next
    delta = hirestimer_delta/1000000
    PrintL "Time to perform 100 parse$: ", format$(delta, "#0.000000")
    
    
    hirestimer_get
    for n = 1 to 100
      x = parsef$(buffer, ",", n)
    Next
    deltaF = hirestimer_delta/1000000
    PrintL "Time to perform 100 parseF$:", format$(deltaF, "#0.000000")
    PrintL format$(delta/deltaF, "#.000") + "x faster"
    PrintL
    ' ---- ---- ---- ---- ---- ----
    
    
    hirestimer_get
    for n = 1 to 100
      x = grab$(buffer, "(", ")", n)
    Next
    delta = hirestimer_delta/1000000
    PrintL "Time to perform 100 grab$: ", format$(delta, "#0.000000")
    
    
    hirestimer_get
    for n = 1 to 100
      x = grabf$(buffer, "(", ")", n)
    Next
    deltaF = hirestimer_delta/1000000
    PrintL "Time to perform 100 grabF$:", format$(deltaF, "#0.000000")
    PrintL format$(delta/deltaF, "#.000") + "x faster"
    PrintL
    ' ---- ---- ---- ---- ---- ----
    printl "---Press a key to end---"
    WaitKey
    
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Replies: 6
    Last Post: 10-05-2013, 12:21
  2. Next thinBasic: ZIP file handling
    By ErosOlmi in forum thinBasic vaporware
    Replies: 2
    Last Post: 29-01-2012, 19:56
  3. How fast is your CPU
    By Michael Clease in forum Shout Box Area
    Replies: 5
    Last Post: 05-02-2010, 09:42

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •