VB Code question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rasta475@gmail.com

    #1

    VB Code question

    I am working with a Compact Framework project that was written in
    VB.Net using Visual Studio .Net 2003. That said I have been given the
    task of making it run "faster". I am a C# programmer and I know there
    are statistics out there for different ways to do the same thing an
    which is faster.

    Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
    than int.Parse(MyStr ingVariable);

    I was wondering if there were such stats for VB.Net like using the
    older VB6 type methods of InStr and Mid versus using
    MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?

    Does anyone have a reference for this and maybe how I can improve
    performance on an app that was written by a VB6 developer who just
    learned VB.Net and applied a lot of VB6 coding practices?

    Note: I do not wish to cause a battle between C# and VB.Net or VB6
    developers here. Just looking for info.

  • Mythran

    #2
    Re: VB Code question


    <rasta475@gmail .comwrote in message
    news:1153929984 .941062.19180@i 3g2000cwc.googl egroups.com...
    >I am working with a Compact Framework project that was written in
    VB.Net using Visual Studio .Net 2003. That said I have been given the
    task of making it run "faster". I am a C# programmer and I know there
    are statistics out there for different ways to do the same thing an
    which is faster.
    >
    Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
    than int.Parse(MyStr ingVariable);
    >
    I was wondering if there were such stats for VB.Net like using the
    older VB6 type methods of InStr and Mid versus using
    MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?
    >
    Does anyone have a reference for this and maybe how I can improve
    performance on an app that was written by a VB6 developer who just
    learned VB.Net and applied a lot of VB6 coding practices?
    >
    Note: I do not wish to cause a battle between C# and VB.Net or VB6
    developers here. Just looking for info.
    >
    I could have sworn that you couldn't cast a string variable to an int in
    C#....I guess I'll need to try it. In any case, simple casting won't really
    speed up an application much. And regardless of language used, it's really
    how the app was designed in the first place. Refactoring code would be a
    good start. Take a look at some of the methods, see if you could logically
    speed them up by rewriting them altogether. Check loops to make sure the
    amount of iterations is minimized. Check logic to make sure they are only
    performing complex calculations if and when they are needed.

    There are a lot of things too look for in order to speed up applications.
    Primarily though, the major slow-down that I've pulled my hair out over is
    other people's loops. For example, a loop that is set up to find a record.
    If they find the record they are looking for, they set a variable that's
    declared outside the loop...AND KEEP LOOPING! Why? I dunno, but breaking
    the loop right then could save LOTS of time ... just one example :)

    Anywho, hth.

    Mythran


    Comment

    • Mythran

      #3
      Re: VB Code question

      It seems in my post I just made that I used the term Refractor (If i
      remember correctly) out of context. Basically, I mean take a look at the
      overall picture of the code you are looking at and see if there's anything
      sticking out that doesn't belong. Then take a look at the code piece by
      piece...in manageable chunks...

      :) Guess I'm just making up words as I go along (or definitions to existing
      words)

      Mythran


      Comment

      • Jim Wooley

        #4
        Re: VB Code question

        I am working with a Compact Framework project that was written in
        VB.Net using Visual Studio .Net 2003. That said I have been given the
        task of making it run "faster". I am a C# programmer and I know there
        are statistics out there for different ways to do the same thing an
        which is faster.
        >
        Ex. Casting variables in C# I know the (int)MyStringVa riable; is
        slower than int.Parse(MyStr ingVariable);
        >
        I was wondering if there were such stats for VB.Net like using the
        older VB6 type methods of InStr and Mid versus using
        MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?
        >
        Does anyone have a reference for this and maybe how I can improve
        performance on an app that was written by a VB6 developer who just
        learned VB.Net and applied a lot of VB6 coding practices?
        I have some performance comparisons of CInt, Integer.Parse, Integer.TryPars e,
        etc at
        http://devauthority.com/blogs/jwoole...02/15/747.aspx. In general,
        it is often best to try makeing performance comparisons yourself. Also, there
        is a point in which you need to balance performance and maintainability .
        Sometimes saving 2 ticks isn't worth spending 2 days each time you need to
        maintain the code, but in other times it is. Learning to balance these needs
        is the art of programming.

        Jim Wooley



        Comment

        • Cor Ligthert [MVP]

          #5
          Re: VB Code question

          Rasta,

          It is forever nice that people are searching for performance in looping,
          casting, and all those things that takes parts of nanoseconds.

          Have a look at how you are using your screen or other external devices. The
          repaint of a little part of your screen takes in every system more
          performance than millions times those things as I wrote above.

          Have you by instance a fancy icon running, have than a look at that, maybe
          it is eating up most of your processor time.

          Just my first thought,

          Cor

          <rasta475@gmail .comschreef in bericht
          news:1153929984 .941062.19180@i 3g2000cwc.googl egroups.com...
          >I am working with a Compact Framework project that was written in
          VB.Net using Visual Studio .Net 2003. That said I have been given the
          task of making it run "faster". I am a C# programmer and I know there
          are statistics out there for different ways to do the same thing an
          which is faster.
          >
          Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
          than int.Parse(MyStr ingVariable);
          >
          I was wondering if there were such stats for VB.Net like using the
          older VB6 type methods of InStr and Mid versus using
          MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?
          >
          Does anyone have a reference for this and maybe how I can improve
          performance on an app that was written by a VB6 developer who just
          learned VB.Net and applied a lot of VB6 coding practices?
          >
          Note: I do not wish to cause a battle between C# and VB.Net or VB6
          developers here. Just looking for info.
          >

          Comment

          • tomb

            #6
            Re: VB Code question

            rasta475@gmail. com wrote:
            >I am working with a Compact Framework project that was written in
            >VB.Net using Visual Studio .Net 2003. That said I have been given the
            >task of making it run "faster". I am a C# programmer and I know there
            >are statistics out there for different ways to do the same thing an
            >which is faster.
            >
            >Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
            >than int.Parse(MyStr ingVariable);
            >
            >I was wondering if there were such stats for VB.Net like using the
            >older VB6 type methods of InStr and Mid versus using
            >MyStringVariab le.Contains() or MyStringVariabl e.SubString()?
            >
            >Does anyone have a reference for this and maybe how I can improve
            >performance on an app that was written by a VB6 developer who just
            >learned VB.Net and applied a lot of VB6 coding practices?
            >
            >Note: I do not wish to cause a battle between C# and VB.Net or VB6
            >developers here. Just looking for info.
            >
            >
            >
            The main thing I would look at is object instantiation - it is a
            resource killer. Better to have an object hang around for a while
            longer than to keep making a new one. That's my 2 cents.

            T

            Comment

            • Patrice

              #7
              Re: VB Code question

              IMO the first step would be to try to find out where the time budget is
              mostly spent. IMO it's unlikely that a cast or something similar will
              produce a visible difference. If you are able to define the area where the
              time is mostly spent, you'll be able to give a closer look for possible
              improvments (caching, avoiding uneeded work, better algo or whatever else).

              --
              Patrice

              <rasta475@gmail .coma écrit dans le message de news:
              1153929984.9410 62.19180@i3g200 0c...legrou ps.com...
              >I am working with a Compact Framework project that was written in
              VB.Net using Visual Studio .Net 2003. That said I have been given the
              task of making it run "faster". I am a C# programmer and I know there
              are statistics out there for different ways to do the same thing an
              which is faster.
              >
              Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
              than int.Parse(MyStr ingVariable);
              >
              I was wondering if there were such stats for VB.Net like using the
              older VB6 type methods of InStr and Mid versus using
              MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?
              >
              Does anyone have a reference for this and maybe how I can improve
              performance on an app that was written by a VB6 developer who just
              learned VB.Net and applied a lot of VB6 coding practices?
              >
              Note: I do not wish to cause a battle between C# and VB.Net or VB6
              developers here. Just looking for info.
              >

              Comment

              • AMercer

                #8
                RE: VB Code question

                I am working with a Compact Framework project that was written in
                VB.Net using Visual Studio .Net 2003. That said I have been given the
                task of making it run "faster". I am a C# programmer and I know there
                are statistics out there for different ways to do the same thing an
                which is faster.
                >
                Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
                than int.Parse(MyStr ingVariable);
                >
                I was wondering if there were such stats for VB.Net like using the
                older VB6 type methods of InStr and Mid versus using
                MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?
                >
                Does anyone have a reference for this and maybe how I can improve
                performance on an app that was written by a VB6 developer who just
                learned VB.Net and applied a lot of VB6 coding practices?
                I went through the vb6 to vb.net and faced the same issue. The
                documentation contains some guidelines re performance, and in general, you
                should follow them. When converting code, I did that except where it meant a
                lot of work for little gain.

                I also used the profiler nprof (it is freeware, others are available). It
                exposes bottlenecks at the function level (not statement level), and that is
                all you need for vb.net. It exposed a few things I was doing foolishly in
                ..net, eg:

                1. Making long strings by concatenating many small pieces using the given
                string operations. Use stringbuilder instead.

                2. Using Mid$ assignments in loops against big strings. This a vb6 natural
                that does not perform well in .net. It is similar to #1 above.

                3. I was using Debug.Assert(xx x,yyy) in a loop where yyy was an expensive
                function call.

                I found nprof to be very productive in improving performance. I would run
                my program under nprof's control, and examine the tree-like output to find
                where I spent the most amount of time. In vb, that usually reduced to a
                piece of the vb library, eg mid$ operations. You can look at the code that
                calls the offending function and recode a small area. For me, the biggest
                offender was sloppy string handling in loops.


                Comment

                • tommaso.gastaldi@uniroma1.it

                  #9
                  Re: VB Code question

                  Yes string handling in .net is really terrible!!

                  Whenever meaningful use always stringbuilder.

                  Also the try/catch structure, if exceptions really
                  occurs, is one of the worst things one can put
                  in a loop: a real suicide... :)

                  -t

                  AMercer ha scritto:
                  I am working with a Compact Framework project that was written in
                  VB.Net using Visual Studio .Net 2003. That said I have been given the
                  task of making it run "faster". I am a C# programmer and I know there
                  are statistics out there for different ways to do the same thing an
                  which is faster.

                  Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
                  than int.Parse(MyStr ingVariable);

                  I was wondering if there were such stats for VB.Net like using the
                  older VB6 type methods of InStr and Mid versus using
                  MyStringVariabl e.Contains() or MyStringVariabl e.SubString()?

                  Does anyone have a reference for this and maybe how I can improve
                  performance on an app that was written by a VB6 developer who just
                  learned VB.Net and applied a lot of VB6 coding practices?
                  >
                  I went through the vb6 to vb.net and faced the same issue. The
                  documentation contains some guidelines re performance, and in general, you
                  should follow them. When converting code, I did that except where it meant a
                  lot of work for little gain.
                  >
                  I also used the profiler nprof (it is freeware, others are available). It
                  exposes bottlenecks at the function level (not statement level), and that is
                  all you need for vb.net. It exposed a few things I was doing foolishly in
                  .net, eg:
                  >
                  1. Making long strings by concatenating many small pieces using the given
                  string operations. Use stringbuilder instead.
                  >
                  2. Using Mid$ assignments in loops against big strings. This a vb6 natural
                  that does not perform well in .net. It is similar to #1 above.
                  >
                  3. I was using Debug.Assert(xx x,yyy) in a loop where yyy was an expensive
                  function call.
                  >
                  I found nprof to be very productive in improving performance. I would run
                  my program under nprof's control, and examine the tree-like output to find
                  where I spent the most amount of time. In vb, that usually reduced to a
                  piece of the vb library, eg mid$ operations. You can look at the code that
                  calls the offending function and recode a small area. For me, the biggest
                  offender was sloppy string handling in loops.

                  Comment

                  • Chris Dunaway

                    #10
                    Re: VB Code question

                    rasta475@gmail. com wrote:
                    I am working with a Compact Framework project that was written in
                    VB.Net using Visual Studio .Net 2003. That said I have been given the
                    I had an app written for the CF for .Net 1.1. When I recompiled the
                    app using .Net 2.0 CF, it ran *much* faster. One operation that
                    normally took about 30 - 40 seconds, now only takes about 5. So in
                    addition to the other replies, if you can rebuild it for CF 2.0, then
                    that should help as well.

                    Comment

                    • Larry Lard

                      #11
                      Re: VB Code question

                      rasta475@gmail. com wrote:
                      I am working with a Compact Framework project that was written in
                      VB.Net using Visual Studio .Net 2003. That said I have been given the
                      task of making it run "faster". I am a C# programmer and I know there
                      are statistics out there for different ways to do the same thing an
                      which is faster.
                      The best statistics are those derived from your application itself. Can
                      you say which line of code is taking the most processor time? If you
                      don't know you should find out.

                      Ex. Casting variables in C# I know the (int)MyStringVa riable; is slower
                      than int.Parse(MyStr ingVariable);
                      Considerably slower, since the former doesn't actually compile.


                      --
                      Larry Lard
                      larrylard@googl email.com
                      The address is real, but unread - please reply to the group
                      For VB and C# questions - tell us which version

                      Comment

                      Working...