VB vs C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary K

    VB vs C#

    I first started with the C language using TurboC moving up to the full C++ with both borland/ms extensions. For the last couple of (dry) years, I have not needed to do full bore projects. As a result I switched to VB to make those quick util progs. Now that I am back into full(+1/2)-time coding, and using .NET now, I was wondering which direction would be better to take. I realise that I can create different 'modules' using either language and add them into a final project, but at the moment I am a one man team, so all the code will be mine. Which one is better for speed? and size? I've already noticed that VB.NET takes a lot of the drudgery out of code typing by auto-completing/formating a lot more than C# does, but C# provides a lot more control over events and interfaces. Does anyone have any thoughts or facts to put forward? I am interested in hearing what side other people have chosen and the reasons for it.
  • Klaus H. Probst

    #2
    Re: VB vs C#

    The differences are not relevant enough to matter. C# is *marginally* faster
    in some instances because the compiler produces a bit more efficient IL. It
    also has some features that VB# lacks, such as unsafe blocks and so on. On
    the other hand, as you point out, VB# has some nicer coding aides.

    If you're writing the average business app it should come down to using
    whatever language you feel comfortable with.


    --
    _______________ _____
    Klaus H. Probst, MVP
    Great prices on a large selection of domains. Find the pefect domain for your new startup.



    "Gary K" <__garyk@trcare .org.au__> wrote in message
    news:8DAF8BE4-450E-40B7-9D08-3CD796FE051E@mi crosoft.com...[color=blue]
    > I first started with the C language using TurboC moving up to the full C++[/color]
    with both borland/ms extensions. For the last couple of (dry) years, I have
    not needed to do full bore projects. As a result I switched to VB to make
    those quick util progs. Now that I am back into full(+1/2)-time coding, and
    using .NET now, I was wondering which direction would be better to take. I
    realise that I can create different 'modules' using either language and add
    them into a final project, but at the moment I am a one man team, so all the
    code will be mine. Which one is better for speed? and size? I've already
    noticed that VB.NET takes a lot of the drudgery out of code typing by
    auto-completing/formating a lot more than C# does, but C# provides a lot
    more control over events and interfaces. Does anyone have any thoughts or
    facts to put forward? I am interested in hearing what side other people have
    chosen and the reasons for it.


    Comment

    • Klaus H. Probst

      #3
      Re: VB vs C#

      The differences are not relevant enough to matter. C# is *marginally* faster
      in some instances because the compiler produces a bit more efficient IL. It
      also has some features that VB# lacks, such as unsafe blocks and so on. On
      the other hand, as you point out, VB# has some nicer coding aides.

      If you're writing the average business app it should come down to using
      whatever language you feel comfortable with.


      --
      _______________ _____
      Klaus H. Probst, MVP
      Great prices on a large selection of domains. Find the pefect domain for your new startup.



      "Gary K" <__garyk@trcare .org.au__> wrote in message
      news:8DAF8BE4-450E-40B7-9D08-3CD796FE051E@mi crosoft.com...[color=blue]
      > I first started with the C language using TurboC moving up to the full C++[/color]
      with both borland/ms extensions. For the last couple of (dry) years, I have
      not needed to do full bore projects. As a result I switched to VB to make
      those quick util progs. Now that I am back into full(+1/2)-time coding, and
      using .NET now, I was wondering which direction would be better to take. I
      realise that I can create different 'modules' using either language and add
      them into a final project, but at the moment I am a one man team, so all the
      code will be mine. Which one is better for speed? and size? I've already
      noticed that VB.NET takes a lot of the drudgery out of code typing by
      auto-completing/formating a lot more than C# does, but C# provides a lot
      more control over events and interfaces. Does anyone have any thoughts or
      facts to put forward? I am interested in hearing what side other people have
      chosen and the reasons for it.


      Comment

      • Cor Ligthert

        #4
        Re: VB vs C#

        Hi Klaus,

        New here?
        [color=blue]
        > The differences are not relevant enough to matter. C# is *marginally*[/color]
        faster[color=blue]
        > in some instances because the compiler produces a bit more efficient IL.[/color]

        There are situations where VB is *marginally* faster because it can use the
        Microsoft.Visua l basic namespace which contents a few functions which have
        more performance than the single Net namespace.

        However the most regulars in the dotnet newsgroups languages.vb and
        languages.cshar p say only that it is a matter of preference which language
        you choose, both languages have (for vb with option strict on of course) the
        same performance.

        Cor





        Comment

        • Cor Ligthert

          #5
          Re: VB vs C#

          Hi Klaus,

          New here?
          [color=blue]
          > The differences are not relevant enough to matter. C# is *marginally*[/color]
          faster[color=blue]
          > in some instances because the compiler produces a bit more efficient IL.[/color]

          There are situations where VB is *marginally* faster because it can use the
          Microsoft.Visua l basic namespace which contents a few functions which have
          more performance than the single Net namespace.

          However the most regulars in the dotnet newsgroups languages.vb and
          languages.cshar p say only that it is a matter of preference which language
          you choose, both languages have (for vb with option strict on of course) the
          same performance.

          Cor





          Comment

          • Cor Ligthert

            #6
            Re: VB vs C#

            I forgot the

            :-)

            Cor


            Comment

            • Cor Ligthert

              #7
              Re: VB vs C#

              I forgot the

              :-)

              Cor


              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: VB vs C#

                Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=blue][color=green]
                > > The differences are not relevant enough to matter. C# is *marginally*[/color]
                > faster[color=green]
                > > in some instances because the compiler produces a bit more efficient IL.[/color]
                >
                > There are situations where VB is *marginally* faster because it can use the
                > Microsoft.Visua l basic namespace which contents a few functions which have
                > more performance than the single Net namespace.[/color]

                A C# developer can use the Microsoft.Visua lBasic namespace if they
                really want to. I don't remember seeing any examples where it's faster
                than can be achieved by not using it, however.
                [color=blue]
                > However the most regulars in the dotnet newsgroups languages.vb and
                > languages.cshar p say only that it is a matter of preference which language
                > you choose, both languages have (for vb with option strict on of course) the
                > same performance.[/color]

                Well, very similar performance, at least.

                --
                Jon Skeet - <skeet@pobox.co m>
                Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                If replying to the group, please do not mail me too

                Comment

                • Jon Skeet [C# MVP]

                  #9
                  Re: VB vs C#

                  Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=blue][color=green]
                  > > The differences are not relevant enough to matter. C# is *marginally*[/color]
                  > faster[color=green]
                  > > in some instances because the compiler produces a bit more efficient IL.[/color]
                  >
                  > There are situations where VB is *marginally* faster because it can use the
                  > Microsoft.Visua l basic namespace which contents a few functions which have
                  > more performance than the single Net namespace.[/color]

                  A C# developer can use the Microsoft.Visua lBasic namespace if they
                  really want to. I don't remember seeing any examples where it's faster
                  than can be achieved by not using it, however.
                  [color=blue]
                  > However the most regulars in the dotnet newsgroups languages.vb and
                  > languages.cshar p say only that it is a matter of preference which language
                  > you choose, both languages have (for vb with option strict on of course) the
                  > same performance.[/color]

                  Well, very similar performance, at least.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                  If replying to the group, please do not mail me too

                  Comment

                  • Cor Ligthert

                    #10
                    Re: VB vs C#

                    Hi Jon,
                    [color=blue][color=green]
                    > > There are situations where VB is *marginally* faster because it can use[/color][/color]
                    the[color=blue][color=green]
                    > > Microsoft.Visua l basic namespace which contents a few functions which[/color][/color]
                    have[color=blue][color=green]
                    > > more performance than the single Net namespace.[/color]
                    >
                    > A C# developer can use the Microsoft.Visua lBasic namespace if they
                    > really want to. I don't remember seeing any examples where it's faster
                    > than can be achieved by not using it, however.[/color]

                    We did some test now already again a some long time ago in the language.vb
                    group (I did although with comments and test from the others as Jay B.).

                    The Find from a string is twice as fast as the indexOf method with a string.
                    I was also supprissed because I have no real VB classic background, so I
                    never use that (still not), as I often told you I think that the 1 as start
                    of an index is the best however, I am used to the zero to start an index.

                    The indexOff however outclassed the Find when it is with a real defined char
                    at least 10 times in performance (the char Find does not exist).

                    Not so long ago I did also test with the Replace and was expecting the same
                    result. However that MB find had the same speed as the Regex. The
                    string.replace was amazing enough the fastest with the stringbuilder.r eplace
                    (that is the one I like) on a very good second place (only a slight
                    difference). The test are done by more persons on more places in the world
                    on different computers and the methode is checked also by those persons.

                    The MB replace and the Regex was 10 to 100 times slower dependable on the
                    situation 1000 times a short string or 10 times a long string than the
                    string.replace. (It was a very simple Regex).

                    I hope this gives you some idea's

                    Cor



                    Comment

                    • Cor Ligthert

                      #11
                      Re: VB vs C#

                      Hi Jon,
                      [color=blue][color=green]
                      > > There are situations where VB is *marginally* faster because it can use[/color][/color]
                      the[color=blue][color=green]
                      > > Microsoft.Visua l basic namespace which contents a few functions which[/color][/color]
                      have[color=blue][color=green]
                      > > more performance than the single Net namespace.[/color]
                      >
                      > A C# developer can use the Microsoft.Visua lBasic namespace if they
                      > really want to. I don't remember seeing any examples where it's faster
                      > than can be achieved by not using it, however.[/color]

                      We did some test now already again a some long time ago in the language.vb
                      group (I did although with comments and test from the others as Jay B.).

                      The Find from a string is twice as fast as the indexOf method with a string.
                      I was also supprissed because I have no real VB classic background, so I
                      never use that (still not), as I often told you I think that the 1 as start
                      of an index is the best however, I am used to the zero to start an index.

                      The indexOff however outclassed the Find when it is with a real defined char
                      at least 10 times in performance (the char Find does not exist).

                      Not so long ago I did also test with the Replace and was expecting the same
                      result. However that MB find had the same speed as the Regex. The
                      string.replace was amazing enough the fastest with the stringbuilder.r eplace
                      (that is the one I like) on a very good second place (only a slight
                      difference). The test are done by more persons on more places in the world
                      on different computers and the methode is checked also by those persons.

                      The MB replace and the Regex was 10 to 100 times slower dependable on the
                      situation 1000 times a short string or 10 times a long string than the
                      string.replace. (It was a very simple Regex).

                      I hope this gives you some idea's

                      Cor



                      Comment

                      • Jon Skeet [C# MVP]

                        #12
                        Re: VB vs C#

                        Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=blue][color=green]
                        > > A C# developer can use the Microsoft.Visua lBasic namespace if they
                        > > really want to. I don't remember seeing any examples where it's faster
                        > > than can be achieved by not using it, however.[/color]
                        >
                        > We did some test now already again a some long time ago in the language.vb
                        > group (I did although with comments and test from the others as Jay B.).
                        >
                        > The Find from a string is twice as fast as the indexOf method with a string.[/color]

                        I'd be interested to see that thread/benchmark. Do you remember what it
                        was called?

                        It's certainly possible that String.IndexOf hasn't been well-optimised,
                        but I suspect the optimisation could be done just as well in a C#
                        method if necessary.
                        [color=blue]
                        > I was also supprissed because I have no real VB classic background, so I
                        > never use that (still not), as I often told you I think that the 1 as start
                        > of an index is the best however, I am used to the zero to start an index.[/color]

                        Not sure how that's relevant here...
                        [color=blue]
                        > The indexOff however outclassed the Find when it is with a real defined char
                        > at least 10 times in performance (the char Find does not exist).
                        >
                        > Not so long ago I did also test with the Replace and was expecting the same
                        > result. However that MB find had the same speed as the Regex. The
                        > string.replace was amazing enough the fastest with the stringbuilder.r eplace
                        > (that is the one I like) on a very good second place (only a slight
                        > difference). The test are done by more persons on more places in the world
                        > on different computers and the methode is checked also by those persons.[/color]

                        Why is it amazing that String.Replace is fast?
                        [color=blue]
                        > The MB replace and the Regex was 10 to 100 times slower dependable on the
                        > situation 1000 times a short string or 10 times a long string than the
                        > string.replace. (It was a very simple Regex).
                        >
                        > I hope this gives you some idea's[/color]

                        I'm not at all surprised that Regex was fairly slow. People always seem
                        to be recommending that one should use a regex when it's just as simple
                        (and more readable) to use a few string operations.

                        Regular expressions are incredibly powerful, but most of the time that
                        power isn't needed.

                        --
                        Jon Skeet - <skeet@pobox.co m>
                        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                        If replying to the group, please do not mail me too

                        Comment

                        • Jon Skeet [C# MVP]

                          #13
                          Re: VB vs C#

                          Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=blue][color=green]
                          > > A C# developer can use the Microsoft.Visua lBasic namespace if they
                          > > really want to. I don't remember seeing any examples where it's faster
                          > > than can be achieved by not using it, however.[/color]
                          >
                          > We did some test now already again a some long time ago in the language.vb
                          > group (I did although with comments and test from the others as Jay B.).
                          >
                          > The Find from a string is twice as fast as the indexOf method with a string.[/color]

                          I'd be interested to see that thread/benchmark. Do you remember what it
                          was called?

                          It's certainly possible that String.IndexOf hasn't been well-optimised,
                          but I suspect the optimisation could be done just as well in a C#
                          method if necessary.
                          [color=blue]
                          > I was also supprissed because I have no real VB classic background, so I
                          > never use that (still not), as I often told you I think that the 1 as start
                          > of an index is the best however, I am used to the zero to start an index.[/color]

                          Not sure how that's relevant here...
                          [color=blue]
                          > The indexOff however outclassed the Find when it is with a real defined char
                          > at least 10 times in performance (the char Find does not exist).
                          >
                          > Not so long ago I did also test with the Replace and was expecting the same
                          > result. However that MB find had the same speed as the Regex. The
                          > string.replace was amazing enough the fastest with the stringbuilder.r eplace
                          > (that is the one I like) on a very good second place (only a slight
                          > difference). The test are done by more persons on more places in the world
                          > on different computers and the methode is checked also by those persons.[/color]

                          Why is it amazing that String.Replace is fast?
                          [color=blue]
                          > The MB replace and the Regex was 10 to 100 times slower dependable on the
                          > situation 1000 times a short string or 10 times a long string than the
                          > string.replace. (It was a very simple Regex).
                          >
                          > I hope this gives you some idea's[/color]

                          I'm not at all surprised that Regex was fairly slow. People always seem
                          to be recommending that one should use a regex when it's just as simple
                          (and more readable) to use a few string operations.

                          Regular expressions are incredibly powerful, but most of the time that
                          power isn't needed.

                          --
                          Jon Skeet - <skeet@pobox.co m>
                          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                          If replying to the group, please do not mail me too

                          Comment

                          • Cor Ligthert

                            #14
                            Re: VB vs C#

                            Hi Jon,
                            [color=blue]
                            > I'd be interested to see that thread/benchmark. Do you remember what it
                            > was called?[/color]

                            It can get it using Google however showing the thread there is so much not
                            to the point in it, I do not want to show it to you, I pasted the test in
                            bellow (The Jon was another Jon with which it started, there are also some
                            crapy thing in like the one I call Cor stupid, that was because there where
                            so many solutions I said for fun you can use the split also, and than they
                            started to believe that and I had to show that it was not a good idea).
                            Although the methode from Jon was the fastest.
                            [color=blue]
                            > Not sure how that's relevant here...[/color]

                            To show you that I was suprized too.
                            [color=blue]
                            > Why is it amazing that String.Replace is fast?[/color]

                            It is not that the String.Replace is fast, I found it amazing that the
                            immutable String.replace was faster.
                            [color=blue]
                            > Regular expressions are incredibly powerful, but most of the time that
                            > power isn't needed.[/color]

                            Same idea.

                            Cor

                            \\\
                            Private Sub Button1_Click(B yVal sender _
                            As Object, ByVal e As System.EventArg s) Handles Button1.Click
                            If Me.TextBox1.Tex t = "" Then
                            Me.label1.Text = "Enter strings in uper textbox"
                            Exit Sub
                            End If
                            If Not IsNumeric(Me.Te xtBox2.Text) Then
                            Me.label1.Text = "Enter value in down textbox"
                            Exit Sub
                            End If
                            TestString.Buil d(Me.TextBox1.T ext.ToString, CInt(Me.TextBox 2.Text))
                            Dim delimiter As String
                            If TestString.Stri ngToTest.Length > 3 Then
                            delimiter = TestString.Stri ngToTest.Substr ing(0, 3)
                            Else
                            Exit Sub
                            End If
                            Dim i As Integer
                            Dim labeltext As New System.Text.Str ingBuilder
                            Dim count As Integer
                            Dim testname As String
                            For i = 1 To 3
                            Dim StartTick As Integer = Environment.Tic kCount
                            Select Case i
                            Case 1
                            testname = "Jay B, string "
                            count = Test1(TestStrin g.StringToTest, delimiter)
                            Case 2
                            testname = "Jon, string "
                            count = Test2(TestStrin g.StringToTest, delimiter)
                            Case 3
                            testname = "Jon, but with indexof"
                            count = Test3(TestStrin g.StringToTest, delimiter)
                            End Select
                            Dim Elapsed As Integer = Environment.Tic kCount - StartTick
                            labeltext.Appen d(testname & "count: " & _
                            count & " Elapsed : " & Elapsed.ToStrin g & vbCrLf)
                            Next
                            delimiter = delimiter.Subst ring(0, 1)
                            labeltext.Appen d("characters " & vbCrLf)
                            For i = 1 To 6
                            Dim StartTick As Integer = Environment.Tic kCount
                            Select Case i
                            Case 1
                            testname = "Jay B, string "
                            count = Test1(TestStrin g.StringToTest, delimiter)
                            Case 2
                            testname = "Jon, string "
                            count = Test2(TestStrin g.StringToTest, delimiter)
                            Case 3
                            testname = "Jon, but with indexof "
                            count = Test3(TestStrin g.StringToTest, delimiter)
                            Case 4
                            If TestString.Stri ngToTest.Length < 599999 Then
                            testname = "Cor stupid "
                            count = Test4(TestStrin g.StringToTest, delimiter)
                            Else
                            testname = "Skipped test"
                            End If
                            Case 5
                            testname = "Jay B char do until "
                            count = test5(TestStrin g.StringToTest, delimiter)
                            Case 6
                            testname = "Jay B char for each "
                            count = test6(TestStrin g.StringToTest, delimiter)
                            End Select
                            Dim Elapsed As Integer = Environment.Tic kCount - StartTick
                            labeltext.Appen d(testname & "count: " & _
                            count & " Elapsed : " & Elapsed.ToStrin g & vbCrLf)
                            Next
                            Me.label1.Text = labeltext.ToStr ing

                            End Sub
                            Private Sub Form1_Load(ByVa l sender As Object, ByVal _
                            e As System.EventArg s) Handles MyBase.Load
                            Me.Button1.Text = "start test"
                            End Sub
                            Public Function Test1(ByVal input As String, ByVal delimiter _
                            As String) As Integer 'Jay B 1(string)
                            Dim count, index As Integer
                            index = input.IndexOf(d elimiter)
                            Do Until index < 0
                            count += 1
                            index = input.IndexOf(d elimiter, index + 1)
                            Loop
                            Return count
                            End Function
                            Public Function Test2(ByVal strInput As String, ByVal strDelimiter _
                            As String) As Int32 'Jon (string)
                            Dim iStart As Int32, iCount As Int32, iResult As Int32
                            iStart = 1
                            iCount = 0
                            Do
                            iResult = InStr(iStart, strInput, strDelimiter)
                            If iResult = 0 Then Exit Do
                            iCount += 1
                            iStart = iResult + 1
                            Loop
                            Return iCount
                            End Function
                            Public Function Test3(ByVal input As String, ByVal delimiter _
                            As String) As Integer 'Jon with indexof(x,x,x)
                            Dim iStart As Int32, iCount As Int32, iResult As Int32
                            iStart = 0
                            iCount = 0
                            Do
                            iResult = input.IndexOf(d elimiter, iStart)
                            If iResult = -1 Then Exit Do
                            iCount += 1
                            iStart = iResult + 1
                            Loop
                            Return iCount
                            End Function
                            Public Function Test4(ByVal input As String, ByVal delimiter _
                            As String) As Integer 'Cor stupid
                            Dim teststring As String() = Split(input, delimiter)
                            Return teststring.Leng th - 1
                            End Function
                            Public Function test5(ByVal input As String, ByVal _
                            delimiter As Char) As Integer 'Jay 1(char)
                            Dim count, index As Integer
                            index = input.IndexOf(d elimiter)
                            Do Until index < 0
                            count += 1
                            index = input.IndexOf(d elimiter, index + 1)
                            Loop
                            Return count
                            End Function
                            Public Shared Function test6(ByVal input As String, _
                            ByVal delimiter As Char) As Integer 'JayB 2(char)
                            Dim count As Integer
                            For Each ch As Char In input
                            If ch = delimiter Then
                            count += 1
                            End If
                            Next ch
                            Return count
                            End Function
                            End Class
                            Public Class TestString
                            Private Shared mStringTest As String
                            Public Shared ReadOnly Property StringToTest() As String
                            Get
                            Return mStringTest
                            End Get
                            End Property
                            Public Shared Sub Build(ByVal strToTest As String, ByVal x As Integer)
                            Dim strTest As New System.Text.Str ingBuilder
                            Dim strTextbox As String() = Split(strToTest , vbCrLf)
                            Do While strTest.ToStrin g.Length < x
                            Dim i As Integer
                            For i = 0 To strTextbox.Leng th - 1
                            Dim y As Integer
                            For y = 0 To i
                            If strTest.ToStrin g.Length < x / 2 Then
                            strTest.Append( strTest.ToStrin g & strTextbox(i))
                            Else
                            strTest.Append( strTest.ToStrin g.Substring(0, x / 2) _
                            & strTextbox(i))
                            End If

                            Next
                            Next
                            Loop
                            mStringTest = strTest.ToStrin g.Substring(0, x)
                            End Sub
                            End Class


                            Comment

                            • Cor Ligthert

                              #15
                              Re: VB vs C#

                              Hi Jon,
                              [color=blue]
                              > I'd be interested to see that thread/benchmark. Do you remember what it
                              > was called?[/color]

                              It can get it using Google however showing the thread there is so much not
                              to the point in it, I do not want to show it to you, I pasted the test in
                              bellow (The Jon was another Jon with which it started, there are also some
                              crapy thing in like the one I call Cor stupid, that was because there where
                              so many solutions I said for fun you can use the split also, and than they
                              started to believe that and I had to show that it was not a good idea).
                              Although the methode from Jon was the fastest.
                              [color=blue]
                              > Not sure how that's relevant here...[/color]

                              To show you that I was suprized too.
                              [color=blue]
                              > Why is it amazing that String.Replace is fast?[/color]

                              It is not that the String.Replace is fast, I found it amazing that the
                              immutable String.replace was faster.
                              [color=blue]
                              > Regular expressions are incredibly powerful, but most of the time that
                              > power isn't needed.[/color]

                              Same idea.

                              Cor

                              \\\
                              Private Sub Button1_Click(B yVal sender _
                              As Object, ByVal e As System.EventArg s) Handles Button1.Click
                              If Me.TextBox1.Tex t = "" Then
                              Me.label1.Text = "Enter strings in uper textbox"
                              Exit Sub
                              End If
                              If Not IsNumeric(Me.Te xtBox2.Text) Then
                              Me.label1.Text = "Enter value in down textbox"
                              Exit Sub
                              End If
                              TestString.Buil d(Me.TextBox1.T ext.ToString, CInt(Me.TextBox 2.Text))
                              Dim delimiter As String
                              If TestString.Stri ngToTest.Length > 3 Then
                              delimiter = TestString.Stri ngToTest.Substr ing(0, 3)
                              Else
                              Exit Sub
                              End If
                              Dim i As Integer
                              Dim labeltext As New System.Text.Str ingBuilder
                              Dim count As Integer
                              Dim testname As String
                              For i = 1 To 3
                              Dim StartTick As Integer = Environment.Tic kCount
                              Select Case i
                              Case 1
                              testname = "Jay B, string "
                              count = Test1(TestStrin g.StringToTest, delimiter)
                              Case 2
                              testname = "Jon, string "
                              count = Test2(TestStrin g.StringToTest, delimiter)
                              Case 3
                              testname = "Jon, but with indexof"
                              count = Test3(TestStrin g.StringToTest, delimiter)
                              End Select
                              Dim Elapsed As Integer = Environment.Tic kCount - StartTick
                              labeltext.Appen d(testname & "count: " & _
                              count & " Elapsed : " & Elapsed.ToStrin g & vbCrLf)
                              Next
                              delimiter = delimiter.Subst ring(0, 1)
                              labeltext.Appen d("characters " & vbCrLf)
                              For i = 1 To 6
                              Dim StartTick As Integer = Environment.Tic kCount
                              Select Case i
                              Case 1
                              testname = "Jay B, string "
                              count = Test1(TestStrin g.StringToTest, delimiter)
                              Case 2
                              testname = "Jon, string "
                              count = Test2(TestStrin g.StringToTest, delimiter)
                              Case 3
                              testname = "Jon, but with indexof "
                              count = Test3(TestStrin g.StringToTest, delimiter)
                              Case 4
                              If TestString.Stri ngToTest.Length < 599999 Then
                              testname = "Cor stupid "
                              count = Test4(TestStrin g.StringToTest, delimiter)
                              Else
                              testname = "Skipped test"
                              End If
                              Case 5
                              testname = "Jay B char do until "
                              count = test5(TestStrin g.StringToTest, delimiter)
                              Case 6
                              testname = "Jay B char for each "
                              count = test6(TestStrin g.StringToTest, delimiter)
                              End Select
                              Dim Elapsed As Integer = Environment.Tic kCount - StartTick
                              labeltext.Appen d(testname & "count: " & _
                              count & " Elapsed : " & Elapsed.ToStrin g & vbCrLf)
                              Next
                              Me.label1.Text = labeltext.ToStr ing

                              End Sub
                              Private Sub Form1_Load(ByVa l sender As Object, ByVal _
                              e As System.EventArg s) Handles MyBase.Load
                              Me.Button1.Text = "start test"
                              End Sub
                              Public Function Test1(ByVal input As String, ByVal delimiter _
                              As String) As Integer 'Jay B 1(string)
                              Dim count, index As Integer
                              index = input.IndexOf(d elimiter)
                              Do Until index < 0
                              count += 1
                              index = input.IndexOf(d elimiter, index + 1)
                              Loop
                              Return count
                              End Function
                              Public Function Test2(ByVal strInput As String, ByVal strDelimiter _
                              As String) As Int32 'Jon (string)
                              Dim iStart As Int32, iCount As Int32, iResult As Int32
                              iStart = 1
                              iCount = 0
                              Do
                              iResult = InStr(iStart, strInput, strDelimiter)
                              If iResult = 0 Then Exit Do
                              iCount += 1
                              iStart = iResult + 1
                              Loop
                              Return iCount
                              End Function
                              Public Function Test3(ByVal input As String, ByVal delimiter _
                              As String) As Integer 'Jon with indexof(x,x,x)
                              Dim iStart As Int32, iCount As Int32, iResult As Int32
                              iStart = 0
                              iCount = 0
                              Do
                              iResult = input.IndexOf(d elimiter, iStart)
                              If iResult = -1 Then Exit Do
                              iCount += 1
                              iStart = iResult + 1
                              Loop
                              Return iCount
                              End Function
                              Public Function Test4(ByVal input As String, ByVal delimiter _
                              As String) As Integer 'Cor stupid
                              Dim teststring As String() = Split(input, delimiter)
                              Return teststring.Leng th - 1
                              End Function
                              Public Function test5(ByVal input As String, ByVal _
                              delimiter As Char) As Integer 'Jay 1(char)
                              Dim count, index As Integer
                              index = input.IndexOf(d elimiter)
                              Do Until index < 0
                              count += 1
                              index = input.IndexOf(d elimiter, index + 1)
                              Loop
                              Return count
                              End Function
                              Public Shared Function test6(ByVal input As String, _
                              ByVal delimiter As Char) As Integer 'JayB 2(char)
                              Dim count As Integer
                              For Each ch As Char In input
                              If ch = delimiter Then
                              count += 1
                              End If
                              Next ch
                              Return count
                              End Function
                              End Class
                              Public Class TestString
                              Private Shared mStringTest As String
                              Public Shared ReadOnly Property StringToTest() As String
                              Get
                              Return mStringTest
                              End Get
                              End Property
                              Public Shared Sub Build(ByVal strToTest As String, ByVal x As Integer)
                              Dim strTest As New System.Text.Str ingBuilder
                              Dim strTextbox As String() = Split(strToTest , vbCrLf)
                              Do While strTest.ToStrin g.Length < x
                              Dim i As Integer
                              For i = 0 To strTextbox.Leng th - 1
                              Dim y As Integer
                              For y = 0 To i
                              If strTest.ToStrin g.Length < x / 2 Then
                              strTest.Append( strTest.ToStrin g & strTextbox(i))
                              Else
                              strTest.Append( strTest.ToStrin g.Substring(0, x / 2) _
                              & strTextbox(i))
                              End If

                              Next
                              Next
                              Loop
                              mStringTest = strTest.ToStrin g.Substring(0, x)
                              End Sub
                              End Class


                              Comment

                              Working...