getting elapsed time in milliseconds

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Baier

    getting elapsed time in milliseconds

    Hi there,

    I need to know how to get the elapsed time in milliseconds. I tried
    time_t start,end;
    time(start);
    do_something();
    time(end);

    double dif = difftime(end, start);

    but this only returns the elapsed time in seconds.
    So how can I get it in milliseconds?


    Thanks for hlep

    Thomas
  • WW

    #2
    Re: getting elapsed time in milliseconds

    Thomas Baier wrote:[color=blue]
    > I need to know how to get the elapsed time in milliseconds. I tried[/color]
    [SNIP][color=blue]
    > So how can I get it in milliseconds?[/color]

    By a high resolution timer facility provided by your operating system, if it
    provides one. Not possible to do only using standard C++ language features.
    Please post your question to a newsgroup dedicated to yiur
    compiler/platform.

    --
    WW aka Attila


    Comment

    • Thomas Baier

      #3
      Re: getting elapsed time in milliseconds

      Thomas Baier wrote:

      I'm working under Suse Linux 8.2 with g++. Maybe anybody in this newgroup
      could answer my question now. Or could anybody tell me a good newsgroup to
      post?


      Thomas

      Comment

      • Alf P. Steinbach

        #4
        Re: getting elapsed time in milliseconds

        On Sat, 20 Sep 2003 19:26:50 +0200, Thomas Baier <thomas@tho-bai.de> wrote:
        [color=blue]
        >Thomas Baier wrote:
        >
        >I'm working under Suse Linux 8.2 with g++. Maybe anybody in this newgroup
        >could answer my question now. Or could anybody tell me a good newsgroup to
        >post?[/color]

        This group is not "please find a newsgroup for me".

        Please don't post any more such questions (read the FAQ etc. about
        topicality, in other words, RTFM).

        That said, try [comp.os.linux.d evelopment.*].

        Comment

        • J. Campbell

          #5
          Re: getting elapsed time in milliseconds

          Thomas Baier <thomas@tho-bai.de> wrote in message news:<3f6c881d$ 0$23106$9b4e6d9 3@newsread2.arc or-online.net>...[color=blue]
          > Hi there,
          >
          > I need to know how to get the elapsed time in milliseconds. I tried
          > time_t start,end;
          > time(start);
          > do_something();
          > time(end);
          >
          > double dif = difftime(end, start);
          >
          > but this only returns the elapsed time in seconds.
          > So how can I get it in milliseconds?
          >
          >
          > Thanks for hlep
          >
          > Thomas[/color]

          The following will do what you want:


          int main(){
          int clo = clock();
          //do stuff
          cout << (clock() - clo) << endl;
          return 0;
          }

          Comment

          • Kevin Goodsell

            #6
            Re: getting elapsed time in milliseconds

            J. Campbell wrote:[color=blue]
            > Thomas Baier <thomas@tho-bai.de> wrote in message news:<3f6c881d$ 0$23106$9b4e6d9 3@newsread2.arc or-online.net>...
            >[color=green]
            >>So how can I get it in milliseconds?
            >>[/color]
            >
            > The following will do what you want:
            >
            >
            > int main(){
            > int clo = clock();
            > //do stuff
            > cout << (clock() - clo) << endl;
            > return 0;
            > }[/color]

            clock() is not a function for retrieving elapsed (real) time, and it's
            result is not measured in milliseconds. clock() gives *processor time*,
            and the precision it uses depends on the implementation.

            -Kevin
            --
            My email address is valid, but changes periodically.
            To contact me please use the address from a recent posting.

            Comment

            • J. Campbell

              #7
              Re: getting elapsed time in milliseconds

              Kevin Goodsell <usenet1.spamfr ee.fusion@never box.com> wrote in message news:<cdmbb.111 3$vS.633@newsre ad3.news.pas.ea rthlink.net>...[color=blue]
              > J. Campbell wrote:[color=green]
              > > Thomas Baier <thomas@tho-bai.de> wrote in message news:<3f6c881d$ 0$23106$9b4e6d9 3@newsread2.arc or-online.net>...
              > >[color=darkred]
              > >>So how can I get it in milliseconds?
              > >>[/color]
              > >
              > > The following will do what you want:
              > >
              > >
              > > int main(){
              > > int clo = clock();
              > > //do stuff
              > > cout << (clock() - clo) << endl;
              > > return 0;
              > > }[/color]
              >
              > clock() is not a function for retrieving elapsed (real) time, and it's
              > result is not measured in milliseconds. clock() gives *processor time*,
              > and the precision it uses depends on the implementation.
              >
              > -Kevin[/color]

              Thanks for the heads-up. On my implimentation, clock() returns
              milliseconds with circa 15 ms precision, and I'd assumed (always
              imprudent) that it worked the same across the board. I dug a little
              and learned of the CLOCKS_PER_SEC constant, which will help a bit for
              gross measurements. Thanks for keeping me on the
              straight-and-narrow...

              Comment

              Working...