Results 1 to 15 of 15

Thread: Let's build... IntegerString

Threaded View

  1. #1

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Let's build... IntegerString

    This is an idea that popped up in the faster InStrRev thread: a replacement of String that is zero based and has more logical functions. I ended up building a Class Module, which you can't of course use in the same way you've used to use Strings. It also wastes some more memory, but in the other hand it allows us to do speed optimizations that otherwise would make things more complex to use as you'd need to initialize and clean up separately. With Class Module you have Initialize and Terminate events to handle that.

    So this is what I have ended up this far: code removed, see second post

    I haven't really thought of the procedure names carefully at the moment, so those are likely to change. I'm also thinking about separating them more so that there is always only a minimal amount of parameters, to keep final syntax easy to read.

    So anyways, is this better than regular strings? Let us make a benchmark of a regular string usage:
    Code:
    ' in Form1
    Option Explicit
    
    Private Sub Command1_Click()
        Dim sngStart As Single, lngA As Long, strResult As String
        
        sngStart = Timer
        
        For lngA = 1 To 100000
            strResult = strResult & "A!"
        Next lngA
        
        Command1.Caption = Format$(Timer - sngStart, "0.00000") & " - " & Len(strResult)
    End Sub
    
    Private Sub Command2_Click()
        Dim sngStart As Single, lngA As Long, strResult As New IntegerString
        
        sngStart = Timer
        
        For lngA = 1 To 100000
            strResult.ValueAppend "A!"
        Next lngA
        
        Command2.Caption = Format$(Timer - sngStart, "0.00000") & " - " & Len(strResult)
    End Sub
    Both add a string "A!" into the end of the string 100000 times, thus resulting into a string that is 200000 characters long. When I compiled this code using all advanced optimizations, I didn't actually expect much: afterall, each adding requires a ReDim Preserve into the integer array. I was surprised:

    The native string way took 20 seconds! I knew it was slow, but I didn't remember it was that slow. Now how about IntegerString? It was done immediately, in about 0.05 seconds. The result from both is the same, a string of 200000 characters.

    So does this look like something that is worth to develop further?


    Edit!
    Adding before the IntegerString in the other hand is far slower, that needs some rethinking on how it should be done. Currently it runs for over 50 seconds and that isn't acceptable.

    Edit #2!
    Now improved to be almost as fast as string. Though it still needs some thinking on the implementation side.
    Last edited by Merri; Apr 25th, 2007 at 08:22 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width