11.2.2 Measuring CPU usage The same psor top commands will also tell you how much cpu and elapsed time a process has used, of course. You can also use the Unix time command to tell you the same thing: $ time myprog 0.050u 0.180s 0:03.68 6.2% 0+0k 0+0io 98pf+0w This tells you that myprog took 3.68 seconds of realtime to run, but spent only 0.05 + 0.18 = 0.23 seconds using the CPU (it must have been doing a lot of I/O). But what if you want to find the fastest strategy among several choices? You could run each one separately and time them, of course. Fortunately, Perl can do it for you with the Benchmarkmodule, by Jarkko Hietaniemi and Tim Bunce. Let’s say that you’re initializing a large hash inside a loop that gets executed many times and you want to know whether it’s faster to use a hash slice or a foreach loop: use Benchmark; timethese (400, { undef => ‘@h{1..10000} = ()’, set => ‘@h{1..10000} = (1)x10000′, loop => ‘$h{$_} = undef for 1..10000′, loopset => ‘$h{$_} = 1 for 1..10000′, });
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services