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. Other Discussions
  3. Clever Code
  4. Elapsed time

Elapsed time

Scheduled Pinned Locked Moved Clever Code
comquestioncode-review
6 Posts 5 Posters 4 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.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    This one took a while to figure out:

    TimeSpan elapsed = DateTime.Now - lastoutput;
    return elapsed.Milliseconds;

    mainly because it made so much sense reading it in English. Yeah, I want the elapsed milliseconds, right? But that's not what I'm getting! Why? Do I really need to post the answer to this one? ;) Marc

    Thyme In The Country

    People are just notoriously impossible. --DavidCrow
    There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
    People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

    C R R 3 Replies Last reply
    0
    • M Marc Clifton

      This one took a while to figure out:

      TimeSpan elapsed = DateTime.Now - lastoutput;
      return elapsed.Milliseconds;

      mainly because it made so much sense reading it in English. Yeah, I want the elapsed milliseconds, right? But that's not what I'm getting! Why? Do I really need to post the answer to this one? ;) Marc

      Thyme In The Country

      People are just notoriously impossible. --DavidCrow
      There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
      People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Doesn't TimeSpan keep track of seconds that have elapsed? The .Milleseconds would just be a number between 0 and 999 and represent some very small part of the total elapsed time. :)

      Chris Meech I am Canadian. [heard in a local bar] I agree with you that my argument is useless. [Red Stateler] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

      M 1 Reply Last reply
      0
      • C Chris Meech

        Doesn't TimeSpan keep track of seconds that have elapsed? The .Milleseconds would just be a number between 0 and 999 and represent some very small part of the total elapsed time. :)

        Chris Meech I am Canadian. [heard in a local bar] I agree with you that my argument is useless. [Red Stateler] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #3

        Chris Meech wrote:

        The .Milleseconds would just be a number between 0 and 999 and represent some very small part of the total elapsed time.

        Exactly. So what I really wanted to return was .TotalMilliseconds. :) Marc

        Thyme In The Country

        People are just notoriously impossible. --DavidCrow
        There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
        People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

        P 1 Reply Last reply
        0
        • M Marc Clifton

          Chris Meech wrote:

          The .Milleseconds would just be a number between 0 and 999 and represent some very small part of the total elapsed time.

          Exactly. So what I really wanted to return was .TotalMilliseconds. :) Marc

          Thyme In The Country

          People are just notoriously impossible. --DavidCrow
          There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
          People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Yep, I saw that.

          1 Reply Last reply
          0
          • M Marc Clifton

            This one took a while to figure out:

            TimeSpan elapsed = DateTime.Now - lastoutput;
            return elapsed.Milliseconds;

            mainly because it made so much sense reading it in English. Yeah, I want the elapsed milliseconds, right? But that's not what I'm getting! Why? Do I really need to post the answer to this one? ;) Marc

            Thyme In The Country

            People are just notoriously impossible. --DavidCrow
            There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
            People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

            R Offline
            R Offline
            Rama Krishna Vavilala
            wrote on last edited by
            #5

            I have also comitted the same mistake! :-O Sometimes you cannot just rely on the method or the property name.

            1 Reply Last reply
            0
            • M Marc Clifton

              This one took a while to figure out:

              TimeSpan elapsed = DateTime.Now - lastoutput;
              return elapsed.Milliseconds;

              mainly because it made so much sense reading it in English. Yeah, I want the elapsed milliseconds, right? But that's not what I'm getting! Why? Do I really need to post the answer to this one? ;) Marc

              Thyme In The Country

              People are just notoriously impossible. --DavidCrow
              There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
              People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

              R Offline
              R Offline
              Russell Morris
              wrote on last edited by
              #6

              :laugh: I did that on the first pass through a quick addon to some automated test cases. These particular test cases were dealing in core areas of my design, and were dealing with carefully constructed test data sets, and I figured it's be nifty to also throw in some data about time spent in the test case. My first reaction to the times were Holy crap that's fast! I rule!. Then it hit me that the test case which apparently took just under 200 milliseconds was accessing an amount of data from disk that simply could not be read from disk in that timeframe, let alone fully processed. I ran it a few more times, and then it dawned on me :)

              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