CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Posts
    11

    Improving Performance

    HI,
    Does the size of a function(number of lines)or procedure affect the performace of the program. i mean the speed of execution etc. Has anybody have any document or suggestion on this.

    Regards
    Hari


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Improving Performance

    It's not really the size that matters (hmm, where did I hear this before). At least, not when compiled. In the VB IDE, your program might run slower when it has more lines, but compiled, it doesn't.
    An example

    ' this
    If a = 1 then a = 2 else a = 3
    ' will run as fast as
    If a = 1 then
    a = 2
    else
    a = 3
    End If



    Why? Simple, you are doing the same. On the other hand:

    ' this
    a = a + 1
    a = a + 1
    ' will be slower as
    a = a + 2



    ' why? You're not doing the same. Ok, the result will be that in both cases a will be 2, but the way you do it is different.
    Again:

    Dim a as integer, b as integer, c as integer, d as integer
    ' runs as fast as
    Dim a as integer
    Dim b as integer
    Dim c as integer
    Dim d as integer
    ' and runs faster then
    Dim a, b, c, d as integer



    Why? There must be allocated 4 spaces in memory, and even in the first statement, they're all at the same line, they will be processed seperately.
    The last statement is slower, because a, b and c don't have a type, and will be variant, which takes up more space (time) in memory.

    As always, it is up to you to keep your code as short as possible, yet as readable as possible. The key thing is to keep the heavy things as short as possible, and as efficient as possible.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured