Function Timer in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yoviesmanda@gmail.com

    Function Timer in C

    I have a problem with C programming. I want to make function timing
    in C, but I don't know how the function or the algorithm. so, I need
    your help to giveme information about it. Thanks.. for your
    attention... see.. you..

  • Ian Collins

    #2
    Re: Function Timer in C

    yoviesmanda@gma il.com wrote:
    I have a problem with C programming. I want to make function timing
    in C, but I don't know how the function or the algorithm. so, I need
    your help to giveme information about it. Thanks.. for your
    attention... see.. you..
    >
    Try comp.lang.c. When you do, make the question a bit clearer, what do
    you want to time?

    --
    Ian Collins.

    Comment

    • Larry Smith

      #3
      Re: Function Timer in C

      yoviesmanda@gma il.com wrote:
      I have a problem with C programming. I want to make function timing
      in C, but I don't know how the function or the algorithm. so, I need
      your help to giveme information about it. Thanks.. for your
      attention... see.. you..
      >
      Look up the clock() function (usually declared in <time.t>):

      man clock

      Comment

      • Victor Bazarov

        #4
        Re: Function Timer in C

        Larry Smith wrote:
        yoviesmanda@gma il.com wrote:
        >I have a problem with C programming. I want to make function timing
        >in C, but I don't know how the function or the algorithm. so, I need
        >your help to giveme information about it. Thanks.. for your
        >attention... see.. you..
        >>
        >
        Look up the clock() function (usually declared in <time.t>):
        <ctime or <time.h>
        man clock
        and woman what?

        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask


        Comment

        • Larry Smith

          #5
          Re: Function Timer in C

          Victor Bazarov wrote:
          Larry Smith wrote:
          >yoviesmanda@gma il.com wrote:
          >>I have a problem with C programming. I want to make function timing
          >>in C, but I don't know how the function or the algorithm. so, I need
          >>your help to giveme information about it. Thanks.. for your
          >>attention.. . see.. you..
          >>>
          >Look up the clock() function (usually declared in <time.t>):
          >
          <ctime or <time.h>
          >
          > man clock
          >
          and woman what?
          >
          V
          Well gee, thanks for correcting the typing error.

          'man' - FYI for Windows folks, that's the Unix manual viewer
          command.

          Ian posted from Solaris, and I mistakenly viewed his
          email headers, instead of the OP's headers, when replying.

          Thanks for the gracious corrections.

          Comment

          • Jim Langston

            #6
            Re: Function Timer in C

            <yoviesmanda@gm ail.comwrote in message
            news:1175757910 .094696.10680@w 1g2000hsg.googl egroups.com...
            >I have a problem with C programming. I want to make function timing
            in C, but I don't know how the function or the algorithm. so, I need
            your help to giveme information about it. Thanks.. for your
            attention... see.. you..
            I generally just use clock().

            unsigned int Start = clock();
            MyFunction();
            unsigned int End = clock();
            std::cout "Elapapsed time: " << End - Start << " ns" << "\n";

            Modify to taste. I think it's ms. On my system it's 1/1000 of a second.


            Comment

            • James Kanze

              #7
              Re: Function Timer in C

              On Apr 6, 7:06 am, "Jim Langston" <tazmas...@rock etmail.comwrote :
              <yoviesma...@gm ail.comwrote in message
              news:1175757910 .094696.10680@w 1g2000hsg.googl egroups.com...
              I have a problem with C programming. I want to make function timing
              in C, but I don't know how the function or the algorithm. so, I need
              your help to giveme information about it. Thanks.. for your
              attention... see.. you..
              I generally just use clock().
              unsigned int Start = clock();
              MyFunction();
              unsigned int End = clock();
              std::cout "Elapapsed time: " << End - Start << " ns" << "\n";
              Modify to taste. I think it's ms.
              It's CLOCKS_PER_SECO ND. Posix requires CLOCKS_PER_SECO ND to be
              1000000, but it may vary on other systems. The best way to
              write the above would be:

              std::cout << "Elapapsed time: "
              << double( End - Start ) / CLOCKS_PER_SEC * 1000.0
              << " ms" << std::endl ;
              On my system it's 1/1000 of a second.
              In the old days, 50 or 60 used to be frequent values.

              --
              James Kanze (Gabi Software) email: james.kanze@gma il.com
              Conseils en informatique orientée objet/
              Beratung in objektorientier ter Datenverarbeitu ng
              9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

              Comment

              • yoviesmanda@gmail.com

                #8
                Re: Function Timer in C

                Thanks for all ...

                Comment

                • Siddhartha Gandhi

                  #9
                  Re: Function Timer in C

                  On Apr 6, 1:06 am, "Jim Langston" <tazmas...@rock etmail.comwrote :
                  <yoviesma...@gm ail.comwrote in message
                  >
                  news:1175757910 .094696.10680@w 1g2000hsg.googl egroups.com...
                  >
                  I have a problem with C programming. I want to make function timing
                  in C, but I don't know how the function or the algorithm. so, I need
                  your help to giveme information about it. Thanks.. for your
                  attention... see.. you..
                  >
                  I generally just use clock().
                  >
                  unsigned int Start = clock();
                  MyFunction();
                  unsigned int End = clock();
                  std::cout "Elapapsed time: " << End - Start << " ns" << "\n";
                  >
                  Modify to taste. I think it's ms. On my system it's 1/1000 of a second.
                  On most systems it is a millisecond. I use std::clock() as well,
                  margin of error of close to 10 milliseconds, though. You could also
                  use gprof or a similar profiler.

                  Comment

                  • James Kanze

                    #10
                    Re: Function Timer in C

                    On Apr 9, 4:11 am, "Siddhartha Gandhi" <siddharthagand hi...@gmail.com >
                    wrote:
                    On Apr 6, 1:06 am, "Jim Langston" <tazmas...@rock etmail.comwrote :
                    <yoviesma...@gm ail.comwrote in message
                    news:1175757910 .094696.10680@w 1g2000hsg.googl egroups.com...
                    >I have a problem with C programming. I want to make function timing
                    in C, but I don't know how the function or the algorithm. so, I need
                    your help to giveme information about it. Thanks.. for your
                    attention... see.. you..
                    I generally just use clock().
                    unsigned int Start = clock();
                    MyFunction();
                    unsigned int End = clock();
                    std::cout "Elapapsed time: " << End - Start << " ns" << "\n";
                    Modify to taste. I think it's ms. On my system it's 1/1000 of a second.
                    On most systems it is a millisecond.
                    On all systems, it's CLOCKS_PER_SEC. Other than that, the only
                    "standard" I know is Posix, which requires a value of 1000000
                    for CLOCKS_PER_SEC, i.e. microseconds. (Linux is also Posix
                    conform in this respect.)
                    I use std::clock() as well,
                    margin of error of close to 10 milliseconds, though.
                    Historically, the granularity was the number of ticks. This
                    certainly isn't the case today, and I don't know of any system
                    which really gives microsecond granularity. (Historically, on
                    the first systems I used, CLOCKS_PER_SEC was 50 in Europe, and
                    60 in America. Which was the granularity.)

                    --
                    James Kanze (GABI Software) email:james.kan ze@gmail.com
                    Conseils en informatique orientée objet/
                    Beratung in objektorientier ter Datenverarbeitu ng
                    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                    Comment

                    Working...