ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
7.2.4 Benchmark - Check and Compare Running Times of Codeuse Benchmark; # timeit(): run $count iterations of the given Perl code, and time it $t = timeit($count, ' The Benchmark module encapsulates a number of routines to help you figure out how long it takes to execute some code a given number of times within a loop. For the For $ perl -MBenchmark -Minteger timethese(100000, { add => '$i += 2', inc => '$i++; $i++' }); __END__ Benchmark: timing 1000000 iterations of add, inc... add: 4 secs ( 4.52 usr 0.00 sys = 4.52 cpu) inc: 6 secs ( 5.32 usr 0.00 sys = 5.32 cpu) The following routines are exported into your namespace if you use the Benchmark module: timeit() timethis() timethese() timediff() timestr() The following routines will be exported into your namespace if you specifically ask that they be imported: clearcache() # clear just the cache element indexed by $key clearallcache() # clear the entire cache disablecache() # do not use the cache enablecache() # resume caching 7.2.4.1 NotesCode is executed in the caller's package. The null loop times are cached, the key being the number of iterations. You can control caching with calls like these: clearcache($key); clearallcache(); disablecache(); enablecache(); Benchmark inherits only from the Exporter class. The elapsed time is measured using time(2) and the granularity is therefore only one second. Times are given in seconds for the whole loop (not divided by the number of iterations). Short tests may produce negative figures because Perl can appear to take longer to execute the empty loop than a short test. The user and system CPU time is measured to millisecond accuracy using times(3). In general, you should pay more attention to the CPU time than to elapsed time, especially if other processes are running on the system. Also, elapsed times of five seconds or more are needed for reasonable accuracy. Because you pass in a string to be evaled instead of a closure to be executed, lexical variables declared with my outside of the eval are not visible. |