Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: storing elapsed time in a variable


From   Gary Longton <[email protected]>
To   [email protected]
Subject   Re: st: storing elapsed time in a variable
Date   Fri, 27 Feb 2004 12:30:32 -0800

Schonlau, Matthias wrote:

I would like to know how much time a portion of my code takes to run. The only way I can think of is using
set rmsg on or c(current_time) before and after the section of the program.

That gives me the time - but it is not automated. I have many different input parameters for this section of the program it would be time consuming to write all times down by hand.

Is there a way of storing elapsed time in a variable?
I tried it without success: the following fails somewhere in the first two lines:
local timestring c(current_time)
tokenize `timestring', parse(":")
di "`1'*`2'*`3' "
local hour1 = real(`1')
local minute1 = real(`2')
local second1 = real(`3')
Take a look at the -profiler- command if you haven't already.
This doesn't answer your question about storing the elapsed time in a variable, but it does get at your aim of timing a portion of code.

-profiler- reports the total time spent in any called program and in each of its component subprograms, along with the number of invocations.

In the program development phase, one approach to timing a particular program segment is to isolate and call that segment as a subprogram within the program, or as a program within a do-file. Then run your main program or do-file with the profiler on, eg.

.profiler on
.profiler clear

- run your program or do-file with embedded program here -

.profiler report
.profiler off


- Gary








*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index