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 / C++ / MFC
  4. calculating time

calculating time

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 3 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.
  • G Offline
    G Offline
    gentleguy
    wrote on last edited by
    #1

    dear all how to calculate time during processing using Time class, anyone has such code? thanks a lot.

    gentleguy

    D P 2 Replies Last reply
    0
    • G gentleguy

      dear all how to calculate time during processing using Time class, anyone has such code? thanks a lot.

      gentleguy

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Are you talking about GetTickCount()?

      "Love people and use things, not love things and use people." - Unknown

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      G 1 Reply Last reply
      0
      • D David Crow

        Are you talking about GetTickCount()?

        "Love people and use things, not love things and use people." - Unknown

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        G Offline
        G Offline
        gentleguy
        wrote on last edited by
        #3

        i just would like to know how to calculate time from start to end processing, which function i can use it? when i used start clock() and end clock(), and CLOCK_PER_SEC, after compiling, output showed didn't declare CLOCK_PER_SEC. but the time is very small after calculate, how to calculate? any road is ok for me. thanks

        gentleguy

        1 Reply Last reply
        0
        • G gentleguy

          dear all how to calculate time during processing using Time class, anyone has such code? thanks a lot.

          gentleguy

          P Offline
          P Offline
          Paresh Chitte
          wrote on last edited by
          #4

          Hi, Please refer below pseudocode,

          long ltime = GetTickCount();
          
          CallYourTimeTakingFunction();
          
          TRACE("Time took = %li\n", GetTickCount() - ltime);
          

          Or,

          CTime startTime = CTime::GetCurrentTime();
          
          CallYourTimeTakingFunction();
          
          CTime endTime = CTime::GetCurrentTime();
          
          CTimeSpan elapsedTime = endTime - startTime;
          

          Hope this will server your purpose. Regards, Paresh.

          G 1 Reply Last reply
          0
          • P Paresh Chitte

            Hi, Please refer below pseudocode,

            long ltime = GetTickCount();
            
            CallYourTimeTakingFunction();
            
            TRACE("Time took = %li\n", GetTickCount() - ltime);
            

            Or,

            CTime startTime = CTime::GetCurrentTime();
            
            CallYourTimeTakingFunction();
            
            CTime endTime = CTime::GetCurrentTime();
            
            CTimeSpan elapsedTime = endTime - startTime;
            

            Hope this will server your purpose. Regards, Paresh.

            G Offline
            G Offline
            gentleguy
            wrote on last edited by
            #5

            #include <time.h> clock_t ckStart,ckEnd,duration =0.0; char buff[1000]; ckStart=clock(); .... ..... ckEnd=clock(); float fDuration=(float)(ckEnd-ckStart)/CLOCK_PER_SEC; sprintf(buff,"speed=%d ms",fAveduration); Message Box (buff,"Time"); what is wrong with these code? output showed no declare CLOCK_PER_SEC. what is problem. thanks

            gentleguy

            P 1 Reply Last reply
            0
            • G gentleguy

              #include <time.h> clock_t ckStart,ckEnd,duration =0.0; char buff[1000]; ckStart=clock(); .... ..... ckEnd=clock(); float fDuration=(float)(ckEnd-ckStart)/CLOCK_PER_SEC; sprintf(buff,"speed=%d ms",fAveduration); Message Box (buff,"Time"); what is wrong with these code? output showed no declare CLOCK_PER_SEC. what is problem. thanks

              gentleguy

              P Offline
              P Offline
              Paresh Chitte
              wrote on last edited by
              #6

              gentleguy wrote:

              float fDuration=(float)(ckEnd-ckStart)/CLOCK_PER_SEC;

              Should be,

              float fDuration=(float)(ckEnd-ckStart)/CLOCKS_PER_SEC;
              

              Change CLOCK_PER_SEC to CLOCK**S**_PER_SEC. Regards, Paresh.

              modified on Friday, May 16, 2008 6:55 AM

              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