Attention: We are retiring the ASP.NET Community Blogs. Learn more >

More timing, different types of tests

Yesterday I blog'ged about some various string splitting times. One thing which amazed me was how slow the VB Split Function was:

========== DoFunction() ==========
Entering DoFunction()...
DoFunction() took 4947.1136 milliseconds.
Entering DoFunction()...
DoFunction() took 4927.0848 milliseconds.
Entering DoFunction()...
DoFunction() took 4927.0848 milliseconds.
========== DoMethod() ==========
Entering DoMethod()...
DoMethod() took 50.072 milliseconds.
Entering DoMethod()...
DoMethod() took 40.0576 milliseconds.
Entering DoMethod()...
DoMethod() took 60.0864 milliseconds.

Today, I changed the tests so that the initial string was much smaller (900 chars versus 900,000) and ran the split operations within loops (as opposed to one big, single Split operation) of 1000 loops. This was done so that if there was any Garbage collection noise in the VB Split FUnction it might be removed from the overall result. The results amazed me somewhat:

========== DoFunction() ==========
Entering DoFunction()...
DoFunction() took 30.0432 milliseconds.
Entering DoFunction()...
DoFunction() took 20.0288 milliseconds.
Entering DoFunction()...
DoFunction() took 30.0432 milliseconds.
========== DoMethod() ==========
Entering DoMethod()...
DoMethod() took 50.072 milliseconds.
Entering DoMethod()...
DoMethod() took 40.0576 milliseconds.
Entering DoMethod()...
DoMethod() took 40.0576 milliseconds.

Related Reading
Timing Your Code

2 Comments

  • How is this a useful comparison if you changed two variables at the same time: size of string and how you loop through it?

  • Todd, I'm really only changing one significant thing: the size of the string. It's just that I'm doing split within a loop so that I can get enough amplification on the results. Here's a summary of the changes that I made:







    *** Changes to how the string is initialized



    For i As Integer = 0 To 100 '<== reduced size

    sb.Append("a b c d" & vbCrLf)

    Next





    *** Changes to DoFunction



    ' Now done within a loop

    For i As Integer = 0 To 1000

    Dim arr as String() = Split(mString, vbCrLf)

    Next



    *** Changes to DoMethod



    ' Now done within a loop

    For i As Integer = 0 To 1000

    Dim arr as String() = Split(mString, vbCrLf)

    Next

Comments have been disabled for this content.