home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / ATRGF21.ZIP / TIMEIT.CMD < prev   
OS/2 REXX Batch file  |  1991-08-03  |  2KB  |  76 lines

  1. /*
  2. program: timeit.cmd
  3. type:    REXXSAA-OS/2
  4. purpose: time the duration of a program (command)
  5. usage:   TIMEIT program [arguments]
  6. needs:   DATERGF.CMD, DATE2STR.CMD
  7. version: 1.1
  8. date:    1991-05-20
  9. changed: 1991-08-02: show duration correctly, if timing over a day, use DATERGF(),
  10.                      DATE2STR() ---Rony G. Flatscher
  11.  
  12. author:  Rony G. Flatscher,
  13.          Wirtschaftsuniversität/Vienna
  14.          RONY@AWIWUW11.BITNET
  15.          flatscher@wu-wien.ac.at
  16.  
  17. All rights reserved, copyrighted 1991, no guarantee that it works without
  18. errors, etc. etc.
  19.  
  20. donated to the public domain granted that you are not charging anything
  21. (money etc.) for it and derivates based upon it, as you did not write it,
  22. etc. if that holds you may bundle it with commercial programs too
  23.  
  24. Please, if you find an error, post me a message describing it, I will
  25. try to fix and rerelease it to the net.
  26. */
  27.  
  28. IF ARG() = 0 | ARG(1) = '?' THEN SIGNAL usage
  29.  
  30. global.format_date = "%yyyy-%mm-%dd"            /* format string for dates */
  31.  
  32. PARSE ARG arguments
  33. SAY '*** TIMEIT:  command:' arguments
  34. SAY '*** TIMEIT: executing command ...'
  35. SAY
  36.  
  37. Start = date('S') time('L') time('R')   /* get date/time & reset timer */
  38. '@CALL 'arguments                       /* execute whatever came in */
  39. End = date('S') time('L') time('E')     /* get date/time & elapsed time */
  40. SAY
  41. SAY '*** TIMEIT: command ended.'
  42.  
  43.  
  44. PARSE VAR Start Starting_DATE Starting_TIME .
  45. PARSE VAR End   Ending_DATE   Ending_TIME   Elapsed_TIME
  46.  
  47. SAY
  48. SAY '*** TIMEIT:  command:' arguments
  49. SAY '*** TIMEIT:  started:' date2str(Starting_DATE,global.format_date) Starting_TIME
  50. SAY '*** TIMEIT:    ended:' date2str(Ending_DATE,global.format_date) Ending_TIME
  51. SAY
  52.  
  53. /* show elapsed seconds (= duration) as "[days] hh:mm:ss" */
  54. fraction = DATERGF(Elapsed_TIME, "SECR")  /* get number of days */
  55.  
  56. IF fraction >= 1 THEN                     /* lasted one or more days */
  57.    tmp = fraction % 1 "day(s) "
  58. ELSE
  59.    tmp = ''
  60.  
  61. /* get formatted time from decimal time fraction */
  62. tmp = tmp || DATERGF(DATERGF(Elapsed_TIME, "SECR"), "FR")
  63.  
  64. SAY '*** TIMEIT: duration:' tmp
  65. SAY '*** TIMEIT: end of TIMEIT.'
  66. EXIT
  67.  
  68. USAGE:
  69. SAY
  70. SAY 'TIMEIT: time the duration of a program (command)'
  71. SAY
  72. SAY 'usage:  TIMEIT program [arguments]'
  73. SAY
  74. EXIT
  75.  
  76.