in reply to gulpng CPU with precision

There really isn't such a thing as "sucking 20% of CPU for a few seconds" The CPU is either crunching on your code with 100% of its might at this precise moment, or its not. The way you phrase it makes it sound like you'd like to gobble 20% of the CPU for a continuous block of seconds. Its the difference between "1 in 5 women are pregnant" and "this woman is 20% pregnant."

I'd recommend using a much finer granularity than sleep, perhaps Time::HiRes has what you are looking for, though I'm not sure if it works under Windows.

use Time::HiRes qw( usleep ); usleep ($microseconds);

-Blake

Replies are listed 'Best First'.
Re: Re: gulpng CPU with precision
by John M. Dlugosz (Monsignor) on Aug 14, 2001 at 06:19 UTC
    If you've seen the tool he's talking about, you'd know what he means.

    I agre it's 100% at any given instant, but averaged over chosen time segment (e.g. 1 second) a mix of tasks will be running a certain percentage of the time. If they don't add up to 100%, you need a faster disk drive. If they do add up to 100%, you need a faster CPU.

      Fair enough, I haven't used that PM tool nor am I a windows expert. I've just seen too many people confuse the CPU issue, and wanted to clear it up a bit.

      -Blake

        Fair enough. I suppose the nomenclature used by PerfMon and other tools is unclear if you don't really know what's going on.

        Implicit in the "load" is a time interval integration. The concept of a percentage breaks down to simply 100/0 values when the scale approaches the frequency at which it alternates between CPU-bound and IO-bound, or the "quantum" slice at which it time-slices.