Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Which of the following is faster

Which of the following is faster

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BabyEmperor
    wrote on last edited by
    #1

    Which of the following is faster : 1. if drRows.Length then end if 2. if drrows.length > 0 then end if 3. if Cbool(drrows.length) then end if Any Suggestions? Thanks

    B B S B 4 Replies Last reply
    0
    • B BabyEmperor

      Which of the following is faster : 1. if drRows.Length then end if 2. if drrows.length > 0 then end if 3. if Cbool(drrows.length) then end if Any Suggestions? Thanks

      B Offline
      B Offline
      Briga
      wrote on last edited by
      #2

      It's rather easy.... test it! Do a 1000000 loop and clock it or in a smarter way use system ticks (read them before and after the loop, the difference is the elapsed time).

      1 Reply Last reply
      0
      • B BabyEmperor

        Which of the following is faster : 1. if drRows.Length then end if 2. if drrows.length > 0 then end if 3. if Cbool(drrows.length) then end if Any Suggestions? Thanks

        B Offline
        B Offline
        Brent Lamborn
        wrote on last edited by
        #3

        Yeah..it would be easy to test. My guess it #1 is the fastest. All three are doing drRows.length but #2 and #3 are both doing an additional operation. "Half this game is ninety percent mental." - Yogi Berra

        1 Reply Last reply
        0
        • B BabyEmperor

          Which of the following is faster : 1. if drRows.Length then end if 2. if drrows.length > 0 then end if 3. if Cbool(drrows.length) then end if Any Suggestions? Thanks

          S Offline
          S Offline
          Steve Pullan
          wrote on last edited by
          #4

          My suggestion (and dare I say the 'correct' way) is to use (#2) because you are comparing "apples with apples" and not forcing an implicit (#1) or explicit (#3) type conversion. The conversion may cause problems in the future and there is no guarantee that (#1) for example will evaluate to Boolean, nor (#3) evaluate to False when the value is zero. ...Steve "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once :-)

          1 Reply Last reply
          0
          • B BabyEmperor

            Which of the following is faster : 1. if drRows.Length then end if 2. if drrows.length > 0 then end if 3. if Cbool(drrows.length) then end if Any Suggestions? Thanks

            B Offline
            B Offline
            BabyEmperor
            wrote on last edited by
            #5

            Thanks Briga, dotnethead, and Steve for your replies. As suggested by briga, i ran a test program with loop of 9999999. When i run the test about many times, each time the result was different. Some times Case #1,#2,#3 all took same time, at times #1 was the fastest, at times #2 , another time #3 and at other times there was a tie b/w the cases. so could not reach a conclusion. As Steve pointed out [it was the reason i posted the question] #1 involves an implicit type conversion [integer is converted to boolean], #2 a comparison and #3 an explicit type conversion, it is difficult to say which would run faster. After much thought i too reached the conclusion that #2 is better [it atleast explains the code better] Thanks every one

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups