Results 1 to 40 of 77

Thread: tips for optimizing vb code

Threaded View

  1. #11
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: tips for optimizing vb code

    That is not a fair test though for at least 3 reasons I can see.

    This is a less biased benchmark...

    VB Code:
    1. Sub Main()
    2.  
    3.         Dim t As Integer
    4.         Dim temp As String
    5.         Dim i, j, k As Integer
    6.  
    7.         For k = 1 To 5
    8.             t = Environment.TickCount
    9.  
    10.             j = 0
    11.             For i = 1 To 1000000000
    12.                 WasteOfTime()
    13.             Next i
    14.  
    15.             t = Environment.TickCount - t
    16.             temp = "Run " & k & ": For: " & t & "ms"
    17.  
    18.             '#####
    19.  
    20.             t = Environment.TickCount
    21.  
    22.             j = 0
    23.             Do Until j = 1000000000
    24.                 j += 1
    25.                 WasteOfTime()
    26.             Loop
    27.  
    28.             t = Environment.TickCount - t
    29.             temp &= ", Do: " & t & "ms"
    30.  
    31.             Console.WriteLine(temp)
    32.         Next k
    33.         Console.ReadLine()
    34.  
    35.     End Sub
    36.  
    37.     Public Sub WasteOfTime()
    38.         Dim s As String = "A"c
    39.         s = Nothing
    40.     End Sub

    NOTE: I haven't got any decent timer code on me at the moment so feel free to replace the Tickcount with something more accurate.

    PS (The wasteoftime method is just to make sure the compiler doesn't discard pointless loops, it also gives the for loop something to do)
    Attached Images Attached Images  
    Last edited by wossname; Mar 17th, 2005 at 07:40 AM.
    I don't live here any more.

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