Thread: Time

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    10

    Question Time

    I need to make program that will work under dos and i need to see how much time user need to press enter two times.

    If i use time () and diftime () (in time.h) they will give mi number of seconds, but i need it in milliseconds besaouse of precision!

    Any ideas???
    Last edited by Autoexes; 10-20-2001 at 10:11 AM.
    #cd pub
    #more beer

  2. #2
    Unregistered
    Guest
    seconds/milliseconds
    printf milliseconds

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    This tops strange questions of the month! Lemme see, is this a curioso question or are we designing weapons systems here?? I couldn't help but to sense a strange urgency in your post, and well I AM a Texan and thus am quite prone to conspiritoral fits and general signs of nervousness when a person who has precisely 1 post on the board from no less than Serbia, asking for " high recision" timing!

    Forgive me if I am a little too paranoid!!

    Perhaps a U.K.er would have better judgement than I!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    10

    Thumbs down

    Well, sorry for my type mistaces, but i think that msg. boards shall not have posts like this!
    If you want to help me that's ok, if you dont wont to help me, that's ok too, but do not express that on this way!!!

    You can ignore my post, send me private message, or something like that, but it is stupid to post that on c forum!

    I think that best solution for all of us is that moderator delete our messages, and i change my 1st.

    p.s. I will not comment things about Serbia!
    Last edited by Autoexes; 10-20-2001 at 12:34 PM.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Use the clock() function.
    It's not quite millisecond precision, but its a lot better than seconds.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > You can ignore my post, send me private message, or
    > something like that, but it is stupid to post that on c forum!

    Someone needs to get a sense of humor. It is a prerequisite for posting on any message board.

    Quzah.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    10

    Thumbs up

    Originally posted by Salem
    Use the clock() function.
    It's not quite millisecond precision, but its a lot better than seconds.
    Ok, thank you very much, but can you post any example?
    I know thet there is clock function i time.h and unix sys call, by i dont know how to utilise that function in "real chalange".
    #cd pub
    #more beer

  8. #8
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    timer example

    clock_t start, stop;

    start = clock();

    for(x=0; x<100000; x++);

    stop = clock();

    clock counts the number of processor 'ticks'.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  9. #9
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    add this to above

    time_in_secs = (stop - start) / CLOCKS_PER_SEC;

    I know you want more precision than seconds but this is a start
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    10
    Originally posted by C_Coder
    add this to above

    time_in_secs = (stop - start) / CLOCKS_PER_SEC;

    I know you want more precision than seconds but this is a start
    I have read some man pages and found something like this, and there it is written that if i want to use something smaller then seconds i need to remove /CLOCK_PER_SECS because value of that variable is 1000000 or something like that.
    Last edited by Autoexes; 10-21-2001 at 06:30 AM.
    #cd pub
    #more beer

  11. #11
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    clock() counts the number of processor 'ticks' while your program is running not an amount of time. CLOCKS_PER_SEC is a macro which turns the 'ticks' into a time, without using it the result from clock() would be meaningless as how would you know how many 'ticks' there were in an amount of time.
    I don't know how you can achieve millisecond precision but I hope someone can tell you as i'ts bugging the hell out of me!
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    10

    Angry

    I found answer!

    The answer is GetTickCount() in windows.h, wich will return the number of milliseconds from starting the OS.

    Bad side is that this is running only onder Windows
    #cd pub
    #more beer

  13. #13
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    If you want to get millisecond precision under Unix you can use

    gettimeofday(struct timeval*, struct timezone*);

    Cheers.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM