#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    16
    Rep Power
    0

    HELP:need to measure time in C!!!!


    Hi all,
    I am writing a C application that is making a call to a database. I need to measure the time it takes to send a request to the database and getting a reply from the database. I coded this requirement as follows:

    time(&starttime);

    // CALL TO THE DATABASE.
    SEND _REQUEST;

    time(&endtime);
    int time = difftime(endtime,starttime);

    using the functions available in time.h, however this returns the time in seconds which is very slow for the speed I am operating at. My question is ,is there anyway in C(or C++ for that matter) to measure time which provides greater granularity (like milli, micro or nanoseconds). Your input is greatly appreciated.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    What OS are you using?
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    16
    Rep Power
    0
    I am using UNIX to execute my program.
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    Try using gettimeofday(). If you're on a *BSD system, you can also look into microtime() and/or nanotime() (nanotime() exists on FreeBSD, but not OpenBSD or NetBSD)
    Last edited by Scorpions4ever; September 2nd, 2003 at 05:32 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo