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. C#
  4. How can I time a function?

How can I time a function?

Scheduled Pinned Locked Moved C#
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I want to know how long a particular function in my program takes to run. How can I get the number of milliseconds between two DateTime objects? Or is there a better way to do this?

    L R A 3 Replies Last reply
    0
    • L Lost User

      I want to know how long a particular function in my program takes to run. How can I get the number of milliseconds between two DateTime objects? Or is there a better way to do this?

      L Offline
      L Offline
      Limey420
      wrote on last edited by
      #2

      I'm no .net expert so I can only give you the Win32 way. Use QueryPerformanceCounter() and QueryPerformanceFrequency() Very high resolution timer, I used it all the time when doing game development on Win32. Milliseconds aren't really good enough for this sort of timing btw.

      1 Reply Last reply
      0
      • L Lost User

        I want to know how long a particular function in my program takes to run. How can I get the number of milliseconds between two DateTime objects? Or is there a better way to do this?

        R Offline
        R Offline
        RSindia
        wrote on last edited by
        #3

        try this (C#).. double totalMillisecs = (dt2-dt1).TotalMilliseconds; rsankarindia

        L 1 Reply Last reply
        0
        • L Lost User

          I want to know how long a particular function in my program takes to run. How can I get the number of milliseconds between two DateTime objects? Or is there a better way to do this?

          A Offline
          A Offline
          alwz_nikhil
          wrote on last edited by
          #4

          U can use the following idea.. int t1= Environment.TickCount; function(); int t2=Environment.TickCount; int t3=t2-t1; Console.Writleln("Time consumed : " + t3.ToString());

          1 Reply Last reply
          0
          • R RSindia

            try this (C#).. double totalMillisecs = (dt2-dt1).TotalMilliseconds; rsankarindia

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thats what I was after. Thank you. Objects in mirror are closer than they appear

            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