Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: measuring elapsed time of a task evoked in a dos batch file  (Read 11179 times)

0 Members and 1 Guest are viewing this topic.

g2c

    Topic Starter


    Greenhorn

    • Experience: Experienced
    • OS: Windows 8
    measuring elapsed time of a task evoked in a dos batch file
    « on: March 11, 2015, 03:03:05 PM »
    hello,

    i am trying desperately to measure the duration of a task called within a dos batch loop running on a windows 8.1 64 bits and an seriously asking myself if this is at all possible

    Thanks in advance for your help

    Tried the procedure in http://stackoverflow.com/questions/9922 ... batch-file
    the expression
    set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)

    result in "Unbalanced parenthesis." whenever hour < 10

    Tried the procedure in
    http://www.computerhope.com/forum/index ... ic=78053.0

    the expression in bold gives
    "Invalid number. Numeric constants are either decimal (17), hexadecimal (0x11), or octal (021)."
    whenever 8<seconds <10

    echo start time=%TIME%
    set HH=%TIME:~0,2%
    echo Hour=%HH%
    set MM=%TIME:~3,2%
    echo minutes=%MM%
    set /a MM=%MM% * 60
    echo Total Seconds in given minutes=%MM%
    set /a HH=%HH% * 3600
    echo Total seconds in given Hours = %HH%
    set SS=%TIME:~6,2%
    echo seconds= %SS%
    Set /a start=%HH% + %MM% + %SS%
    echo start time in seconds =%start%

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other

    g2c

      Topic Starter


      Greenhorn

      • Experience: Experienced
      • OS: Windows 8
      Re: measuring elapsed time of a task evoked in a dos batch file
      « Reply #2 on: March 11, 2015, 04:40:27 PM »
      thanks a lot, looks exactly what i need

      I am ashamed to admit that i don't know how to use this procedure :(

      Please help

      Guy

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: measuring elapsed time of a task evoked in a dos batch file
      « Reply #3 on: March 11, 2015, 06:57:25 PM »
      It shows you exactly how to use it.
      Quote from: dbenham
      getTimestap.bat can also be used to conveniently compute elapsed time of nearly any time interval, without worrying about the limits of batch arithmetic. This is extremely convenient for timing events.

      Two calls to getTimestamp are used to store the current timestamp at the beginning and end of a process. The timestamps are expressed as milliseconds since midnight, January 1, 1970. Then one more call to getTimestamp is used to compute the interval. The date for the interval is specified as timestamp2 - timestamp1, and the format can provide the elapsed time in whatever units are required.
      Code: [Select]
      @echo off
      setlocal

      call getTimestamp -f {ums} -r t1
      :: Some long running process here
      call getTimestamp -f {ums} -r t2

      :: This computes the elapsed time as decimal hours.
      :: It supports both positive and negative intervals.
      call getTimestamp -d %t2%-%t1% -f "{uhd} hours"

      :: This computes the elapsed time as days, hours, mins, secs, ms
      :: It only supports positive intervals
      call getTimestamp -d %t2%-%t1% -f "{ud} days {hh}:{nn}:{ss}.{fff}" -u

      patio

      • Moderator


      • Genius
      • Maud' Dib
      • Thanked: 1769
        • Yes
      • Experience: Beginner
      • OS: Windows 7
      Re: measuring elapsed time of a task evoked in a dos batch file
      « Reply #4 on: March 11, 2015, 07:19:52 PM »
      You can lead a horse...ahhh  nevermind.
      " Anyone who goes to a psychiatrist should have his head examined. "

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: measuring elapsed time of a task evoked in a dos batch file
      « Reply #5 on: March 11, 2015, 07:22:10 PM »
      What  is the objective?
      It is not about prime lapse.
      Time clasp does not require that much work.

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: measuring elapsed time of a task evoked in a dos batch file
      « Reply #6 on: March 11, 2015, 07:25:11 PM »
      What  is the objective?
      It is not about prime lapse.
      Time clasp does not require that much work.
      I have no idea what prime lapse or Time Clasp are.
      All the user wants is to measure how much time it took to run a routine.  So you get the start time and the end time and subtract.

      Dave Benham wrote a very powerful utility to do this.
      « Last Edit: March 11, 2015, 07:44:33 PM by Squashman »

      g2c

        Topic Starter


        Greenhorn

        • Experience: Experienced
        • OS: Windows 8
        Re: measuring elapsed time of a task evoked in a dos batch file
        « Reply #7 on: March 12, 2015, 01:53:31 AM »
        Thanks Squashman, I saw this example but i don't know where should i put the routine definition: that of getTimestamp  code itself so that the commend interpreter knows where to search for the called code

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: measuring elapsed time of a task evoked in a dos batch file
        « Reply #8 on: March 12, 2015, 05:10:12 AM »
        getTimeStamp is a 2nd batch file that will either need to exist in the same folder as your current batch file or in the SYSTEM PATH.

        Code: [Select]
        @echo off
        setlocal

        :: SETTING THE TIME STAMP BEFORE THE TASK
        :: getTimeStamp is setting a variable %t1% as the start time
        call getTimestamp -f {ums} -r t1
        :: YOUR CODE GOES
        :: DO A BUNCH OF CRAP HERE
        :: BLAH BLAH BLAH BLAH BLAH

        :: SETTING THE TIME STAMP AFTER THE TASK IS DONE.
        :: getTimeStamp is setting a variable %t2% as the end time
        call getTimestamp -f {ums} -r t2

        :: This computes the elapsed time as decimal hours.
        :: It supports both positive and negative intervals.
        call getTimestamp -d %t2%-%t1% -f "{uhd} hours"

        :: This computes the elapsed time as days, hours, mins, secs, ms
        :: It only supports positive intervals
        call getTimestamp -d %t2%-%t1% -f "{ud} days {hh}:{nn}:{ss}.{fff}" -u

        g2c

          Topic Starter


          Greenhorn

          • Experience: Experienced
          • OS: Windows 8
          Re: measuring elapsed time of a task evoked in a dos batch file
          « Reply #9 on: March 12, 2015, 05:26:52 AM »
          Dear Squashman,

          You don't know how much i owe you! I never spent so much time on something so trivia

          Guy

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: measuring elapsed time of a task evoked in a dos batch file
          « Reply #10 on: March 12, 2015, 06:12:32 AM »
          An easier method that you can embed in your batch file was posted on DosTips.com in the thread you started over there.
          http://www.dostips.com/forum/viewtopic.php?p=40395#p40395

          g2c

            Topic Starter


            Greenhorn

            • Experience: Experienced
            • OS: Windows 8
            Re: measuring elapsed time of a task evoked in a dos batch file
            « Reply #11 on: March 12, 2015, 06:58:13 AM »
            Funny, they sent me an email saying my post needs be inspected first and that I should be informed of the result of the investigation :)

            Squashman



              Specialist
            • Thanked: 134
            • Experience: Experienced
            • OS: Other
            Re: measuring elapsed time of a task evoked in a dos batch file
            « Reply #12 on: March 12, 2015, 07:05:32 AM »
            Funny, they sent me an email saying my post needs be inspected first and that I should be informed of the result of the investigation :)
            Yes.  I am one of the moderators. But I turn of the notification saying that the post has been approved.  We only approve the first couple of posts.  If you want notifications for the thread, then subscribe to the topic.

            g2c

              Topic Starter


              Greenhorn

              • Experience: Experienced
              • OS: Windows 8
              Re: measuring elapsed time of a task evoked in a dos batch file
              « Reply #13 on: March 12, 2015, 07:11:54 AM »
              The "simpler" one may exhibit a misbehaviour at midnight

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: measuring elapsed time of a task evoked in a dos batch file
              « Reply #14 on: March 12, 2015, 07:27:55 AM »
              Correct. That is why I suggested using Dave's external batch to call out to.  But Antonio may have some extra code he can tack on for the rollover into another day.