Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: CPU usage for Stata loops (Windows)


From   jhassell@stata.com (James Hassell, StataCorp LP)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: CPU usage for Stata loops (Windows)
Date   Fri, 06 Nov 2009 11:26:52 -0600

Nick Winter <nwinter@virginia.edu> asked why Stata for Windows uses
more CPU time when sleeping for 500 milliseconds than it does when
sleeping for 501 milliseconds.


> On my Windows XP [fully up to date, legal IC Stata 11 :-) ], the
> following consumes 30-50% of my system CPU time, according to the
> Windows Task Manager:
>
> while 1 {
>    sleep 500
> }
>
> Whereas this consumes essentially 0 CPU time:
>
> while 1 {
>    sleep 501
> }
>
>
> (On one computer the first loop consumes 50%, i.e. the total that Stata
> can use on my Dual Core processor; on a different computer it takes
> "only" 30-ish percent.  But on both systems there's a sharp drop to
> essentially nothing in the second loop.
>
> Any ideas why?


Stata does not simply put its process to sleep for the specified amount
of time, because that would make Stata unresponsive and thus prevent the
user from having the ability to break out of the -sleep- command.  Making
Stata unresponsive is not an ideal solution, so Stata uses logic which
allows the process to really sleep for a short interval, and then check
the system's timer to determine if it needs to continue sleeping.
Currently, Stata for Windows attempts to check the system's timer more often
if the -sleep- interval is less than or equal to 500 milliseconds, resulting
in increased CPU usage.  We have reviewed the logic surrounding the -sleep-
command and have determined that we can make an improvement reducing the
CPU load for short sleep intervals.  Look for this change to show up in a
future executable update.  As I alluded, this only affects Stata for Windows.

-- James Hassell
   StataCorp LP
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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