Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to track how long does it take when running a "do file" or a command?

    Normally I have some codes taking much time and I left the machine running by itself. But it should be convenient if there is a code to track how long a do file finish or how long does it take to run a specific command. I am wondering if you can share me your experience about that

  • #2
    One method is to set up a log file, which also documents when the log was initiated and closed.

    Another method is to display the system time. You can add a line of:
    Code:
    display c(current_time)
    at the beginning and end of code to display the time.

    In addition, it's possible to compute the difference as well. E.g.
    Code:
    scalar t1 = c(current_time)
    * SOME PROGRAM
    scalar t2 = c(current_time)
    
    display (clock(t2, "hms") - clock(t1, "hms")) / 1000 " seconds"
    Last edited by Ken Chui; 08 Jul 2021, 07:33.

    Comment


    • #3
      Another thing you can do is
      Code:
      set rmsg on
      With that, after each command (or block of commands in a program or loop) Stata will display a message containing the number of seconds it took to execute that command, along with the current time.

      Comment


      • #4
        I measure how long execution takes with -[P] timer -- Time sections of code by recording and reporting time spent-, and with the user written one liner -timeit-.

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          Another thing you can do is
          Code:
          set rmsg on
          With that, after each command (or block of commands in a program or loop) Stata will display a message containing the number of seconds it took to execute that command, along with the current time.
          Hi Clyde, it is great to turn it on, is there anyway to turn it off then ?

          Comment


          • #6
            Well, this setting is not remembered from one launch of Stata to the next. So exiting Stata and re-starting is one way to turn it off.

            But if you need to keep running Stata and you don't want the messages any more, you can turn it off with, wait for it....

            Code:
            set rmsg off

            Comment

            Working...
            X