-profiler- should still give David almost what he wants, even if he doesn't
use -foreach-. I just tried a -reshape- with -profiler-, and most of the
time spent reshaping was in the the subroutine -Wide-. Presumably there is
another subroutine -Long-. If these are where most of the time is spent
reshaping David's data, he'll something not too far from the right answer to
his question.
Cheers,
Mark
Quoting Nick Cox <[email protected]>:
> It is indeed what David wants, but
> -profiler- neither promises to
> give this information nor in
> fact gives it.
>
> "The record includes only the time spent
> directly in a program and not time spent
> in other programs that are themselves
> invoked by the program -- these latter
> times are recorded with the invoked program."
>
> You may be carrying over ideas associated
> with -for- in other languages in which
> -for- controls a loop. -for- in Stata
> does that too, but it is nothing other
> than an .ado that runs other commands
> or programs. (There also can be a major
> interpretive overhead. I used to use
> -for- a long time ago to cycle over
> stuff, until it became clear that -for-
> itself was sometimes taking many times longer
> than what I wanted.)
>
> In this respect, -for- contrasts sharply
> with -foreach- or -forvalues-, which
> are wired into the executable. Having
> said that, I am not clear that using
> -foreach- here would get the profiling
> desired.
>
> Nick
> [email protected]
>
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of
> > Mark Schaffer
> > Sent: 14 November 2004 16:27
> > To: [email protected]
> > Subject: RE: st: time elapsed within 'for' loops
> >
> >
> > Nick/David,
> >
> > Quoting Nick Cox <[email protected]>:
> >
> > > I doubt it. -for- itself is a command. The fact
> > > that it runs other commands is not reflected
> > > by what the profiler reports,
> >
> > reshape is an ado, and so profiler should report on how much
> > time was spent
> > in reshape, no? I think this is what David wants. Or
> > perhaps I missed the
> > point somewhere.
> >
> > Cheers,
> > Mark
> >
> > > as is explained
> > > in the help Mark quotes here.
> > >
> > > A quite different comment is beware -for-
> > > and the habit of trying to write miniature programs
> > > as a single call to -for-. It is cute when it
> > > works but very inefficient and all too likely to bite you.
> > >
> > > Nick
> > > [email protected]
> > >
> > > Mark Schaffer
> > >
> > > > Try -profiler-; it will probably do what you want. From the
>
> > > > help file:
> > > >
> > > > "profiler is a programmer's command that can help in
> > > > optimizing ado-files
> > > > and other Stata programs. When profiling is turned on,
> > > > profiler on, Stata
> > > > begins keeping a record of each time a program is run and how
>
> > > > much time is
> > > > spent in the program."
> > >
> > > David K Evans
> > >
> > > > > Is there a simple way to see how much time has elapsed while
> a
> > > > > command in the midst of a "for" loop is running?
> > > > >
> > > > > Outside of a loop, I just "set rmsg on" and can see how
> long
> > > each
> > > > > command takes.
> > > > >
> > > > > But if I have, for example,
> > > > >
> > > > > for num 1/10: preserve \ keep if age==X \ reshape [blah
> blah
> > > blah]
> > > > > \
> > > > > save ageX.dta, replace \ restore;
> > > > >
> > > > > and I want to know how long the reshaping took, I'm not sure
> how
> > > to
> > > > > find out. "set rmsg on" only gives me the time for the
> entire
> > > loop.
> > > > >
> > > > > I know about macros to display the time, but I'm not sure
> how
> > > to
> > > > > manipulate them to calculate time elapsed.
> > >
>
> *
> * 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/
>
Prof. Mark Schaffer
Director, CERT
Department of Economics
School of Management & Languages
Heriot-Watt University, Edinburgh EH14 4AS
tel +44-131-451-3494 / fax +44-131-451-3008
email: [email protected]
web: http://www.sml.hw.ac.uk/ecomes
________________________________________________________________
DISCLAIMER:
This e-mail and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to
whom it is addressed. If you are not the intended recipient
you are prohibited from using any of the information contained
in this e-mail. In such a case, please destroy all copies in
your possession and notify the sender by reply e-mail. Heriot
Watt University does not accept liability or responsibility
for changes made to this e-mail after it was sent, or for
viruses transmitted through this e-mail. Opinions, comments,
conclusions and other information in this e-mail that do not
relate to the official business of Heriot Watt University are
not endorsed by it.
________________________________________________________________
*
* 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/