Thread: Evaluate time in C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Location
    Viet nam
    Posts
    9
    Quote Originally Posted by matsp View Post
    The time is not seconds, but "ticks", and there is #define constant in clock.h called CLOCKS_PER_SEC, which you can divide the result by to give you seconds. If you are measuring relatively short times, you should probably also convert your time to float or double.

    --
    Mats
    Can you give me a example,plz!! ^.^
    I have tried in this code:

    int var1,var2,diff;

    var1 = CLOCKS_PER_SEC;

    ab.saveToFile("ATM.txt",key);

    var2= CLOCKS_PER_SEC;

    cout << " :" << var2;

    diff = var2-var1;

    cout << endl<<diff <<endl;


    and the result is var1 = 1000;
    var 2 =1000
    diff = 0 :|

    And i can't include clock.h

    Thanks!!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, you should use var1= clock() and var2 = clock(), then DIVIDE the resulting difference by CLOCKS_PER_SEC().

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. Checking parts of a structure
    By DocDroopy in forum C Programming
    Replies: 11
    Last Post: 08-05-2002, 07:45 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM