Measuring time of a reply

This is a discussion on Measuring time of a reply within the C++ Programming forums, part of the General Programming Boards category; I would like to know if there is a way in C++ to measure the time that it takes between ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    367

    Measuring time of a reply

    I would like to know if there is a way in C++ to measure the time that it takes between a function is initiated and a value is returned from it.

    Example:

    Code:
    std::cout << "assign a value: ";
    std::cin >> variable:
    (Here I call "std::cin" a function.)

    Here I want to know the time that it takes from that that the program is expecting a value to be assigned to the variable "variable", and that that a value has been assigned to it.

    I would also like to have the time that has been measured returned in a float of seconds and hundreds of seconds, like 3.21 for example.

    Sorry if I don't know the correct terms for everything, I hope you understand what I mean anyway.

  2. #2
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    well, you could use GetTickCount() like so:

    Code:
    float current,last;
    
    last = GetTickCount(); /* get the current ticks since system   
                                              startup
                                             measured in milliseconds*/
    
    // your function
    
    current = (GetTickCount - last)/1000;// take the time elapsed     between the two, and divide by 
                                                            1 thousand to get time in seconds.*/
    printf("Function took %f seconds\n",current);
    Last edited by EvBladeRunnervE; 10-27-2003 at 07:03 AM.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Except this is the C++ board so you would use cout... And you forgot the parentheses on your second call to GetTickCount()
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    You think I'm a noob, but I actually found that with the missing paranthesis out by myself. Yes, it's some float variable named "last", which I can't really figure out what its purpose is, subtracted from the return value of GetTickCount(). Right?

    I actually got this to work!!! The code does what I wanted it to do, I'm very thankful for this =)))
    Last edited by Zewu; 10-27-2003 at 09:23 AM.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    >>current = (GetTickCount - last)/1000;

    If that will compile at all, it's taking the address of the function...not calling it and manipulating the result

    GetTickCount isnt that reliable anyway...If you want any decent, consistant results, use a profiler

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    Then what it is a profiler and how does it work?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21