home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1988 / 15 / timerun.c < prev    next >
C/C++ Source or Header  |  1988-06-28  |  1KB  |  52 lines

  1. /* timerun.c RHS 5/18/88
  2.  *
  3.  * This program times the load and execution time of another program.
  4.  *
  5.  * Return Values set are:
  6.  *   The return value of the 'child' program, or
  7.  *   255 if unsucessful.
  8.  *
  9.  * For MSC 5.x:
  10.  *        cl /Ox /W3 timerun.c
  11.  */
  12.  
  13. #include<time.h>
  14. #include<process.h>
  15. #include<stdio.h>
  16.  
  17. void main(int argc, char **argv);
  18.  
  19. void main(int argc, char **argv)
  20. {
  21.      long start = 0L, end = 0L;
  22.      int retval;
  23.  
  24.      if(argc < 2)
  25.      {
  26.           printf("\nUsage: timerun <program> [args...]");
  27.           printf("\nPurpose: to report the run time of a program in seconds");
  28.           exit(255);
  29.      }
  30.  
  31.      printf("\ntimerun: attempting to run: %s...",argv[1]);
  32.  
  33.      argv++;                       /* set argv to point to argv[1]    */
  34.                                    /* the old argv[1] is now argv[0]  */
  35.  
  36.      start = clock();              /* start the clock ...             */
  37.  
  38.                                    /* run the child                   */
  39.      if((retval = spawnvp(P_WAIT,argv[0],argv)) == -1)
  40.      {
  41.           printf("\ntimerun: Child process failed, aborting...");
  42.           exit(255);
  43.      }
  44.  
  45.      end = clock();                /* get clock after return from child*/
  46.  
  47.      printf("\ntimerun: \"%s\" took %04.02f seconds to load and execute",
  48.           argv[0],(float)(end-start)/CLK_TCK);
  49.  
  50.      exit(retval);                 /* exit with return value of child */
  51. }
  52.