Results 1 to 6 of 6

Thread: Assignment operators

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Assignment operators

    I know that in C++ using +=, -=, ... is faster. I was trying to see if it is faster in VB.NET or not, but I get almost same results. Maybe I'm coding it wrong(I know very very little about .NET)

    can someone look at this, maybe it's kinda wrong. But I almost get the same result by using both kind of operators

    VB Code:
    1. Module Module1
    2.  
    3.     Sub Main()
    4.         Console.WriteLine(OldOps())
    5.         Console.WriteLine(newOps)
    6.         Console.ReadLine()
    7.     End Sub
    8.  
    9.  
    10.  
    11.     Private Function OldOps() As String
    12.         Dim i As Long
    13.         Dim tmp As Byte
    14.         Dim startTime As Date
    15.         startTime = Now()
    16.  
    17.         For i = 1 To 500000000
    18.             tmp = tmp + 1
    19.             tmp = tmp - 1
    20.         Next
    21.  
    22.         Return "OldOps took " & DateDiff(DateInterval.Second, startTime, Now).ToString & " seconds"
    23.  
    24.     End Function
    25.  
    26.     Private Function newOps() As String
    27.         Dim i As Long
    28.         Dim tmp As Byte
    29.         Dim startTime As Date
    30.         startTime = Now()
    31.  
    32.         For i = 1 To 500000000
    33.             tmp += 1
    34.             tmp -= 1
    35.         Next
    36.  
    37.         Return "NewOps took " & DateDiff(DateInterval.Second, startTime, Now).ToString & " seconds"
    38.  
    39.     End Function
    40. End Module
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I dont think you'll see any speed increase from those operators.
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    yeah that's what happened. I though maybe that's not a good test
    But I think i C++ there is a difference in speed
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    i++..?

    in my post woooo hooooo i posted on app i tried to use ++ in this app and it would not compile. Option Strict is On.

    Anyone know whats up with that..? i asume that it has to be done i += 1
    Magiaus

    If I helped give me some points.

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I dont think ++ is suported in VB with or without option strict.
    Dont gain the world and lose your soul

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    I think in C++ the speed increase is because (correct me if I'm wrong!) it complies to ASM as
    Code:
    INC whatever
    instead of
    ADD whatever, 1
    since VB compiles to the MSIL, I don't think you'll see a speed increase.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

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