Time ./a.out equivalent in Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karthigan Srinivasan

    Time ./a.out equivalent in Windows

    Is there an equivant method of

    'time ./a.out'

    in Windows to measure execution time for a program?

    Best Regards,
    Karthigan.
  • santosh

    #2
    Re: Time ./a.out equivalent in Windows

    Karthigan Srinivasan wrote:
    Is there an equivant method of
    >
    'time ./a.out'
    >
    in Windows to measure execution time for a program?
    >
    Best Regards,
    Karthigan.
    Download the package available at the following link:

    <http://unxutils.source forge.net/>

    Comment

    • Keith Thompson

      #3
      Re: Time ./a.out equivalent in Windows

      "Karthigan Srinivasan" <karthigan@eart hlink.netwrites :
      Is there an equivant method of
      >
      'time ./a.out'
      >
      in Windows to measure execution time for a program?
      We don't know. Well, some people here might happen to know, but this
      isn't the place to ask, since your question really isn't about the C
      programming language.

      Try one of the comp.os.ms-windows.* or microsoft.* newsgroups.

      --
      Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
      Nokia
      "We must do something. This is something. Therefore, we must do this."
      -- Antony Jay and Jonathan Lynn, "Yes Minister"

      Comment

      • Bartc

        #4
        Re: Time ./a.out equivalent in Windows

        "Karthigan Srinivasan" <karthigan@eart hlink.netwrote in message
        news:op.t74o4kv wpinhaa@karthig an-desktop...
        Is there an equivant method of
        >
        'time ./a.out'
        >
        in Windows to measure execution time for a program?
        I put together the C program below which vaguely works, but you might get
        ideas on how to do it properly. (I've never used command parameters in C
        before).

        --
        Bart

        #include <stdio.h>
        #include <stdlib.h>
        #include <time.h>
        #include <string.h>

        int main(int n,char **cmds)
        {char cmdstring[260];
        int t;
        int i,m;
        char **p;

        if (n<=1)
        {if (n==1) printf("Usage: %s filename\n",*cm ds);
        return EXIT_FAILURE;
        };

        ++cmds; /* first param of interest, should be exe name */

        /* must check all params combined fit into cmdstring (you can ignore this if
        not posting your code!) */
        m=0;
        p=cmds;
        for (i=2; i<=n; ++i) m+=(strlen(*p++ )+1);
        if (m>sizeof(cmdst ring)) return EXIT_FAILURE;

        /* All the trouble the system went to to separate the params, now we need to
        join them all together again with spaces between */
        /* Hint: if you can use Winmain() instead, the params are already joined up
        */

        strcpy(cmdstrin g,*cmds);
        for (i=3; i<=n; ++i)
        {strcat(cmdstri ng," ");
        strcat(cmdstrin g,*(++cmds));
        };

        printf("Executi ng %s ...\n",cmdstrin g);

        t=clock();

        system(cmdstrin g);

        t=clock()-t;

        printf("Executi on time: %d msec",t);

        return EXIT_SUCCESS;
        }



        Comment

        • santosh

          #5
          Re: Time ./a.out equivalent in Windows

          Bartc wrote:

          <snip>

          I think you should divide the difference by CLOCKS_PER_SEC to get the
          result in seconds. As such your program's result is always zero. This
          is because you are strong a return value of type clock_t into an int.
          Use a clock_t variable.

          Also you could use malloc for concatenating the command arguments to
          deal with large number of/long strings.

          Comment

          • santosh

            #6
            Re: Time ./a.out equivalent in Windows

            Bartc wrote:

            <snip>

            Since your program is paused by the operating system when the command
            given to *system* is executing, both the return values from clock will
            be the same, and thus the difference will always be zero.

            You need to use functions beyond the C standard like POSIX *times*
            function in sys/times.h to do this properly.

            Comment

            • Kaz Kylheku

              #7
              Re: Time ./a.out equivalent in Windows

              On Mar 16, 3:41 pm, "Bartc" <b...@freeuk.co mwrote:
              t=clock();
              >
              system(cmdstrin g);
              >
              t=clock()-t;
              >
              printf("Executi on time: %d msec",t);
              This output lies to the user if CLOCKS_PER_SEC isn't 1000.

              Comment

              • Bartc

                #8
                Re: Time ./a.out equivalent in Windows


                "santosh" <santosh.k83@gm ail.comwrote in message
                news:frk9h0$qbu $1@registered.m otzarella.org.. .
                Bartc wrote:
                >
                <snip>
                >
                Since your program is paused by the operating system when the command
                given to *system* is executing, both the return values from clock will
                be the same, and thus the difference will always be zero.
                That's a good point. clock() should give the execution time of the program
                doing the timing.

                Nevertheless, it seemed to work! Or at least gave sensible results.

                Maybe something to with Windows, and the OP wanted this on Windows.

                --
                Bart


                Comment

                • santosh

                  #9
                  Re: Time ./a.out equivalent in Windows

                  santosh wrote:

                  <snip>

                  Well it is horribly broken in the sense that it will collapse all it's
                  arguments without preserving a space between them. A quick workaround
                  is to enclose all the arguments to the program inside a pair of double
                  quotes. Fixing it is left to the OP. :-)

                  Comment

                  • Bartc

                    #10
                    Re: Time ./a.out equivalent in Windows


                    "santosh" <santosh.k83@gm ail.comwrote in message
                    news:frkcjg$6vd $1@registered.m otzarella.org.. .
                    Bartc wrote:
                    >
                    >>
                    >"santosh" <santosh.k83@gm ail.comwrote in message
                    >news:frk9h0$qb u$1@registered. motzarella.org. ..
                    >>Bartc wrote:
                    >>>
                    >><snip>
                    >>>
                    >>Since your program is paused by the operating system when the command
                    >>given to *system* is executing, both the return values from clock
                    >>will be the same, and thus the difference will always be zero.
                    >>
                    >That's a good point. clock() should give the execution time of the
                    >program doing the timing.
                    >>
                    >Nevertheless , it seemed to work! Or at least gave sensible results.
                    >>
                    >Maybe something to with Windows, and the OP wanted this on Windows.
                    >
                    Here is a more robust version of 'time'. Still not as good as the UNIX
                    version of course. This code is NOT standard C; it depends on
                    *gettimeofday* , which is specific to POSIX systems.
                    >
                    #include <stdio.h>
                    ....
                    gettimeofday(&s tart, NULL);
                    ....

                    Yes, that's pretty comprehensive, compared to my poor effort.

                    I see that you're measuring elapsed time, rather than execution time, which
                    I suppose is a good alternative (I sometimes just use my watch).

                    --
                    Bart


                    Comment

                    • santosh

                      #11
                      Re: Time ./a.out equivalent in Windows

                      Bartc wrote:
                      >
                      "santosh" <santosh.k83@gm ail.comwrote in message
                      news:frk9h0$qbu $1@registered.m otzarella.org.. .
                      >Bartc wrote:
                      >>
                      ><snip>
                      >>
                      >Since your program is paused by the operating system when the command
                      >given to *system* is executing, both the return values from clock
                      >will be the same, and thus the difference will always be zero.
                      >
                      That's a good point. clock() should give the execution time of the
                      program doing the timing.
                      It does. Trouble is, the execution of our program is suspended when the
                      argument to system is running. As far as clock is concerned, no time
                      has elapsed between the call to system and it's return.

                      To stick to pure standard C we will have to use the time function, whose
                      resolution is usually isn't sufficient for use in a "time" command.

                      <snip>

                      Comment

                      • Keith Thompson

                        #12
                        Re: Time ./a.out equivalent in Windows

                        "Bartc" <bc@freeuk.comw rites:
                        "Karthigan Srinivasan" <karthigan@eart hlink.netwrote in message
                        news:op.t74o4kv wpinhaa@karthig an-desktop...
                        >Is there an equivant method of
                        >>
                        >'time ./a.out'
                        >>
                        >in Windows to measure execution time for a program?
                        >
                        I put together the C program below which vaguely works, but you might get
                        ideas on how to do it properly. (I've never used command parameters in C
                        before).
                        [snip]

                        The Unix/Linux "time" command cannot be implemented in purely standard
                        C. There are various versions of the "time" command, some of them
                        built into various shells. It typically reports the wall-clock time,
                        the user-mode CPU time, the system-mode CPU time, and the percentage
                        of time spent in CPU time; it may also report various I/O statistics.

                        --
                        Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                        Nokia
                        "We must do something. This is something. Therefore, we must do this."
                        -- Antony Jay and Jonathan Lynn, "Yes Minister"

                        Comment

                        • Kenny McCormack

                          #13
                          Re: Time ./a.out equivalent in Windows

                          In article <87fxuqcdxg.fsf @kvetch.smov.or g>,
                          Keith Thompson <kst-u@mib.orgwrote:
                          >"Bartc" <bc@freeuk.comw rites:
                          >"Karthigan Srinivasan" <karthigan@eart hlink.netwrote in message
                          >news:op.t74o4k vwpinhaa@karthi gan-desktop...
                          >>Is there an equivant method of
                          >>>
                          >>'time ./a.out'
                          >>>
                          >>in Windows to measure execution time for a program?
                          >>
                          >I put together the C program below which vaguely works, but you might get
                          >ideas on how to do it properly. (I've never used command parameters in C
                          >before).
                          >[snip]
                          >
                          >The Unix/Linux "time" command cannot be implemented in purely standard C.
                          True, given that the C standard doesn't admit of any kind of
                          multi-processing, so the whole concept is moot.

                          You, of all people, ought to know that.

                          Comment

                          • Kenny McCormack

                            #14
                            Re: Time ./a.out equivalent in Windows

                            In article <73068f5f-7fdd-422e-b2e5-14dec045a7fb@s8 g2000prg.google groups.com>,
                            Kaz Kylheku <kkylheku@gmail .comwrote:
                            ....
                            >GetTickCount ...
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >alone the best one available on Windows. The Windows API provides
                            >GetThreadTim es ...
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >and GetProcessTimes ...
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >to launch it with CreateProcess.. .
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >WaitForSingleO bject ...
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >status using GetExitCodeEx.. .
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >collect the times using GetProcessTimes ...
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
                            >and then close both the process and thread handle(s).
                            Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

                            Well done. Your post is completely OT.

                            Comment

                            • jacob navia

                              #15
                              Re: Time ./a.out equivalent in Windows

                              Karthigan Srinivasan wrote:
                              Is there an equivant method of
                              >
                              'time ./a.out'
                              >
                              in Windows to measure execution time for a program?
                              >
                              Best Regards,
                              Karthigan.
                              #include <windows.h>
                              #include <stdio.h>
                              int main(int argc,char *argv[])
                              {
                              int ms;

                              if (argc < 2) {
                              printf(
                              "Usage: %s \"command\" (enclosed in double quotes)\n",
                              argv[0]);
                              return -1;
                              }
                              ms = GetTickCount();
                              system(argv[1]);
                              ms = GetTickCount() - ms;
                              printf("\n'%s'\ nexecuted in %d ms\n",argv[1],ms);
                              return 0;
                              }




                              --
                              jacob navia
                              jacob at jacob point remcomp point fr
                              logiciels/informatique

                              Comment

                              Working...