📄 benchmark.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "Benchmark 3".TH Benchmark 3 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Benchmark \- benchmark running times of Perl code.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 1\& use Benchmark qw(:all) ;\&\& timethis ($count, "code");\&\& # Use Perl code in strings...\& timethese($count, {\& \*(AqName1\*(Aq => \*(Aq...code1...\*(Aq,\& \*(AqName2\*(Aq => \*(Aq...code2...\*(Aq,\& });\&\& # ... or use subroutine references.\& timethese($count, {\& \*(AqName1\*(Aq => sub { ...code1... },\& \*(AqName2\*(Aq => sub { ...code2... },\& });\&\& # cmpthese can be used both ways as well\& cmpthese($count, {\& \*(AqName1\*(Aq => \*(Aq...code1...\*(Aq,\& \*(AqName2\*(Aq => \*(Aq...code2...\*(Aq,\& });\&\& cmpthese($count, {\& \*(AqName1\*(Aq => sub { ...code1... },\& \*(AqName2\*(Aq => sub { ...code2... },\& });\&\& # ...or in two stages\& $results = timethese($count, \& {\& \*(AqName1\*(Aq => sub { ...code1... },\& \*(AqName2\*(Aq => sub { ...code2... },\& },\& \*(Aqnone\*(Aq\& );\& cmpthese( $results ) ;\&\& $t = timeit($count, \*(Aq...other code...\*(Aq)\& print "$count loops of other code took:",timestr($t),"\en";\&\& $t = countit($time, \*(Aq...other code...\*(Aq)\& $count = $t\->iters ;\& print "$count loops of other code took:",timestr($t),"\en";\&\& # enable hires wallclock timing if possible\& use Benchmark \*(Aq:hireswallclock\*(Aq;.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"The Benchmark module encapsulates a number of routines to help youfigure out how long it takes to execute some code..PPtimethis \- run a chunk of code several times.PPtimethese \- run several chunks of code several times.PPcmpthese \- print results of timethese as a comparison chart.PPtimeit \- run a chunk of code and see how long it goes.PPcountit \- see how many times a chunk of code runs in a given time.Sh "Methods".IX Subsection "Methods".IP "new" 10.IX Item "new"Returns the current time. Example:.Sp.Vb 6\& use Benchmark;\& $t0 = new Benchmark;\& # ... your code here ...\& $t1 = new Benchmark;\& $td = timediff($t1, $t0);\& print "the code took:",timestr($td),"\en";.Ve.IP "debug" 10.IX Item "debug"Enables or disable debugging by setting the \f(CW$Benchmark::Debug\fR flag:.Sp.Vb 3\& debug Benchmark 1;\& $t = timeit(10, \*(Aq 5 ** $Global \*(Aq);\& debug Benchmark 0;.Ve.IP "iters" 10.IX Item "iters"Returns the number of iterations..Sh "Standard Exports".IX Subsection "Standard Exports"The following routines will be exported into your namespaceif you use the Benchmark module:.IP "timeit(\s-1COUNT\s0, \s-1CODE\s0)" 10.IX Item "timeit(COUNT, CODE)"Arguments: \s-1COUNT\s0 is the number of times to run the loop, and \s-1CODE\s0 isthe code to run. \s-1CODE\s0 may be either a code reference or a string tobe eval'd; either way it will be run in the caller's package..SpReturns: a Benchmark object..IP "timethis ( \s-1COUNT\s0, \s-1CODE\s0, [ \s-1TITLE\s0, [ \s-1STYLE\s0 ]] )" 10.IX Item "timethis ( COUNT, CODE, [ TITLE, [ STYLE ]] )"Time \s-1COUNT\s0 iterations of \s-1CODE\s0. \s-1CODE\s0 may be a string to eval or acode reference; either way the \s-1CODE\s0 will run in the caller's package.Results will be printed to \s-1STDOUT\s0 as \s-1TITLE\s0 followed by the times.\&\s-1TITLE\s0 defaults to \*(L"timethis \s-1COUNT\s0\*(R" if none is provided. \s-1STYLE\s0determines the format of the output, as described for \fItimestr()\fR below..SpThe \s-1COUNT\s0 can be zero or negative: this means the \fIminimum number of\&\s-1CPU\s0 seconds\fR to run. A zero signifies the default of 3 seconds. Forexample to run at least for 10 seconds:.Sp.Vb 1\& timethis(\-10, $code).Ve.Spor to run two pieces of code tests for at least 3 seconds:.Sp.Vb 1\& timethese(0, { test1 => \*(Aq...\*(Aq, test2 => \*(Aq...\*(Aq}).Ve.Sp\&\s-1CPU\s0 seconds is, in \s-1UNIX\s0 terms, the user time plus the system time ofthe process itself, as opposed to the real (wallclock) time and thetime spent by the child processes. Less than 0.1 seconds is notaccepted (\-0.01 as the count, for example, will cause a fatal runtimeexception)..SpNote that the \s-1CPU\s0 seconds is the \fBminimum\fR time: \s-1CPU\s0 scheduling andother operating system factors may complicate the attempt so that alittle bit more time is spent. The benchmark output will, however,also tell the number of \f(CW$code\fR runs/second, which should be a moreinteresting number than the actually spent seconds..Sp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -