home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
view JSON data
|
view as text
This file was processed as: LaTeX Document
(document/latex).
You can browse this item here: tex
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| LaTeX document text
| default
| |
99%
| file
| LaTeX document, ASCII text
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/281 LaTeX (Subdocument)
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 63 68 61 70 74 65 72 | 7b 54 68 65 20 50 79 74 |\chapter|{The Pyt|
|00000010| 68 6f 6e 20 50 72 6f 66 | 69 6c 65 72 7d 0a 5c 73 |hon Prof|iler}.\s|
|00000020| 74 6d 6f 64 69 6e 64 65 | 78 7b 70 72 6f 66 69 6c |tmodinde|x{profil|
|00000030| 65 7d 0a 5c 73 74 6d 6f | 64 69 6e 64 65 78 7b 70 |e}.\stmo|dindex{p|
|00000040| 73 74 61 74 73 7d 0a 0a | 43 6f 70 79 72 69 67 68 |stats}..|Copyrigh|
|00000050| 74 20 5c 63 6f 70 79 72 | 69 67 68 74 5c 20 31 39 |t \copyr|ight\ 19|
|00000060| 39 34 2c 20 62 79 20 49 | 6e 66 6f 53 65 65 6b 20 |94, by I|nfoSeek |
|00000070| 43 6f 72 70 6f 72 61 74 | 69 6f 6e 2c 20 61 6c 6c |Corporat|ion, all|
|00000080| 20 72 69 67 68 74 73 20 | 72 65 73 65 72 76 65 64 | rights |reserved|
|00000090| 2e 0a 0a 57 72 69 74 74 | 65 6e 20 62 79 20 4a 61 |...Writt|en by Ja|
|000000a0| 6d 65 73 20 52 6f 73 6b | 69 6e 64 25 0a 5c 66 6f |mes Rosk|ind%.\fo|
|000000b0| 6f 74 6e 6f 74 65 7b 0a | 55 70 64 61 74 65 64 20 |otnote{.|Updated |
|000000c0| 61 6e 64 20 63 6f 6e 76 | 65 72 74 65 64 20 74 6f |and conv|erted to|
|000000d0| 20 5c 4c 61 54 65 58 5c | 20 62 79 20 47 75 69 64 | \LaTeX\| by Guid|
|000000e0| 6f 20 76 61 6e 20 52 6f | 73 73 75 6d 2e 20 20 54 |o van Ro|ssum. T|
|000000f0| 68 65 20 72 65 66 65 72 | 65 6e 63 65 73 20 74 6f |he refer|ences to|
|00000100| 0a 74 68 65 20 6f 6c 64 | 20 70 72 6f 66 69 6c 65 |.the old| profile|
|00000110| 72 20 61 72 65 20 6c 65 | 66 74 20 69 6e 20 74 68 |r are le|ft in th|
|00000120| 65 20 74 65 78 74 2c 20 | 61 6c 74 68 6f 75 67 68 |e text, |although|
|00000130| 20 69 74 20 6e 6f 20 6c | 6f 6e 67 65 72 20 65 78 | it no l|onger ex|
|00000140| 69 73 74 73 2e 0a 7d 0a | 0a 50 65 72 6d 69 73 73 |ists..}.|.Permiss|
|00000150| 69 6f 6e 20 74 6f 20 75 | 73 65 2c 20 63 6f 70 79 |ion to u|se, copy|
|00000160| 2c 20 6d 6f 64 69 66 79 | 2c 20 61 6e 64 20 64 69 |, modify|, and di|
|00000170| 73 74 72 69 62 75 74 65 | 20 74 68 69 73 20 50 79 |stribute| this Py|
|00000180| 74 68 6f 6e 20 73 6f 66 | 74 77 61 72 65 0a 61 6e |thon sof|tware.an|
|00000190| 64 20 69 74 73 20 61 73 | 73 6f 63 69 61 74 65 64 |d its as|sociated|
|000001a0| 20 64 6f 63 75 6d 65 6e | 74 61 74 69 6f 6e 20 66 | documen|tation f|
|000001b0| 6f 72 20 61 6e 79 20 70 | 75 72 70 6f 73 65 20 28 |or any p|urpose (|
|000001c0| 73 75 62 6a 65 63 74 20 | 74 6f 20 74 68 65 0a 72 |subject |to the.r|
|000001d0| 65 73 74 72 69 63 74 69 | 6f 6e 20 69 6e 20 74 68 |estricti|on in th|
|000001e0| 65 20 66 6f 6c 6c 6f 77 | 69 6e 67 20 73 65 6e 74 |e follow|ing sent|
|000001f0| 65 6e 63 65 29 20 77 69 | 74 68 6f 75 74 20 66 65 |ence) wi|thout fe|
|00000200| 65 20 69 73 20 68 65 72 | 65 62 79 20 67 72 61 6e |e is her|eby gran|
|00000210| 74 65 64 2c 0a 70 72 6f | 76 69 64 65 64 20 74 68 |ted,.pro|vided th|
|00000220| 61 74 20 74 68 65 20 61 | 62 6f 76 65 20 63 6f 70 |at the a|bove cop|
|00000230| 79 72 69 67 68 74 20 6e | 6f 74 69 63 65 20 61 70 |yright n|otice ap|
|00000240| 70 65 61 72 73 20 69 6e | 20 61 6c 6c 20 63 6f 70 |pears in| all cop|
|00000250| 69 65 73 2c 20 61 6e 64 | 0a 74 68 61 74 20 62 6f |ies, and|.that bo|
|00000260| 74 68 20 74 68 61 74 20 | 63 6f 70 79 72 69 67 68 |th that |copyrigh|
|00000270| 74 20 6e 6f 74 69 63 65 | 20 61 6e 64 20 74 68 69 |t notice| and thi|
|00000280| 73 20 70 65 72 6d 69 73 | 73 69 6f 6e 20 6e 6f 74 |s permis|sion not|
|00000290| 69 63 65 20 61 70 70 65 | 61 72 20 69 6e 0a 73 75 |ice appe|ar in.su|
|000002a0| 70 70 6f 72 74 69 6e 67 | 20 64 6f 63 75 6d 65 6e |pporting| documen|
|000002b0| 74 61 74 69 6f 6e 2c 20 | 61 6e 64 20 74 68 61 74 |tation, |and that|
|000002c0| 20 74 68 65 20 6e 61 6d | 65 20 6f 66 20 49 6e 66 | the nam|e of Inf|
|000002d0| 6f 53 65 65 6b 20 6e 6f | 74 20 62 65 20 75 73 65 |oSeek no|t be use|
|000002e0| 64 20 69 6e 0a 61 64 76 | 65 72 74 69 73 69 6e 67 |d in.adv|ertising|
|000002f0| 20 6f 72 20 70 75 62 6c | 69 63 69 74 79 20 70 65 | or publ|icity pe|
|00000300| 72 74 61 69 6e 69 6e 67 | 20 74 6f 20 64 69 73 74 |rtaining| to dist|
|00000310| 72 69 62 75 74 69 6f 6e | 20 6f 66 20 74 68 65 20 |ribution| of the |
|00000320| 73 6f 66 74 77 61 72 65 | 0a 77 69 74 68 6f 75 74 |software|.without|
|00000330| 20 73 70 65 63 69 66 69 | 63 2c 20 77 72 69 74 74 | specifi|c, writt|
|00000340| 65 6e 20 70 72 69 6f 72 | 20 70 65 72 6d 69 73 73 |en prior| permiss|
|00000350| 69 6f 6e 2e 20 20 54 68 | 69 73 20 70 65 72 6d 69 |ion. Th|is permi|
|00000360| 73 73 69 6f 6e 20 69 73 | 0a 65 78 70 6c 69 63 69 |ssion is|.explici|
|00000370| 74 6c 79 20 72 65 73 74 | 72 69 63 74 65 64 20 74 |tly rest|ricted t|
|00000380| 6f 20 74 68 65 20 63 6f | 70 79 69 6e 67 20 61 6e |o the co|pying an|
|00000390| 64 20 6d 6f 64 69 66 69 | 63 61 74 69 6f 6e 20 6f |d modifi|cation o|
|000003a0| 66 20 74 68 65 20 73 6f | 66 74 77 61 72 65 0a 74 |f the so|ftware.t|
|000003b0| 6f 20 72 65 6d 61 69 6e | 20 69 6e 20 50 79 74 68 |o remain| in Pyth|
|000003c0| 6f 6e 2c 20 63 6f 6d 70 | 69 6c 65 64 20 50 79 74 |on, comp|iled Pyt|
|000003d0| 68 6f 6e 2c 20 6f 72 20 | 6f 74 68 65 72 20 6c 61 |hon, or |other la|
|000003e0| 6e 67 75 61 67 65 73 20 | 28 73 75 63 68 20 61 73 |nguages |(such as|
|000003f0| 20 43 29 0a 77 68 65 72 | 65 69 6e 20 74 68 65 20 | C).wher|ein the |
|00000400| 6d 6f 64 69 66 69 65 64 | 20 6f 72 20 64 65 72 69 |modified| or deri|
|00000410| 76 65 64 20 63 6f 64 65 | 20 69 73 20 65 78 63 6c |ved code| is excl|
|00000420| 75 73 69 76 65 6c 79 20 | 69 6d 70 6f 72 74 65 64 |usively |imported|
|00000430| 20 69 6e 74 6f 20 61 0a | 50 79 74 68 6f 6e 20 6d | into a.|Python m|
|00000440| 6f 64 75 6c 65 2e 0a 0a | 49 4e 46 4f 53 45 45 4b |odule...|INFOSEEK|
|00000450| 20 43 4f 52 50 4f 52 41 | 54 49 4f 4e 20 44 49 53 | CORPORA|TION DIS|
|00000460| 43 4c 41 49 4d 53 20 41 | 4c 4c 20 57 41 52 52 41 |CLAIMS A|LL WARRA|
|00000470| 4e 54 49 45 53 20 57 49 | 54 48 20 52 45 47 41 52 |NTIES WI|TH REGAR|
|00000480| 44 20 54 4f 20 54 48 49 | 53 0a 53 4f 46 54 57 41 |D TO THI|S.SOFTWA|
|00000490| 52 45 2c 20 49 4e 43 4c | 55 44 49 4e 47 20 41 4c |RE, INCL|UDING AL|
|000004a0| 4c 20 49 4d 50 4c 49 45 | 44 20 57 41 52 52 41 4e |L IMPLIE|D WARRAN|
|000004b0| 54 49 45 53 20 4f 46 20 | 4d 45 52 43 48 41 4e 54 |TIES OF |MERCHANT|
|000004c0| 41 42 49 4c 49 54 59 20 | 41 4e 44 0a 46 49 54 4e |ABILITY |AND.FITN|
|000004d0| 45 53 53 2e 20 49 4e 20 | 4e 4f 20 45 56 45 4e 54 |ESS. IN |NO EVENT|
|000004e0| 20 53 48 41 4c 4c 20 49 | 4e 46 4f 53 45 45 4b 20 | SHALL I|NFOSEEK |
|000004f0| 43 4f 52 50 4f 52 41 54 | 49 4f 4e 20 42 45 20 4c |CORPORAT|ION BE L|
|00000500| 49 41 42 4c 45 20 46 4f | 52 20 41 4e 59 0a 53 50 |IABLE FO|R ANY.SP|
|00000510| 45 43 49 41 4c 2c 20 49 | 4e 44 49 52 45 43 54 20 |ECIAL, I|NDIRECT |
|00000520| 4f 52 20 43 4f 4e 53 45 | 51 55 45 4e 54 49 41 4c |OR CONSE|QUENTIAL|
|00000530| 20 44 41 4d 41 47 45 53 | 20 4f 52 20 41 4e 59 20 | DAMAGES| OR ANY |
|00000540| 44 41 4d 41 47 45 53 20 | 57 48 41 54 53 4f 45 56 |DAMAGES |WHATSOEV|
|00000550| 45 52 0a 52 45 53 55 4c | 54 49 4e 47 20 46 52 4f |ER.RESUL|TING FRO|
|00000560| 4d 20 4c 4f 53 53 20 4f | 46 20 55 53 45 2c 20 44 |M LOSS O|F USE, D|
|00000570| 41 54 41 20 4f 52 20 50 | 52 4f 46 49 54 53 2c 20 |ATA OR P|ROFITS, |
|00000580| 57 48 45 54 48 45 52 20 | 49 4e 20 41 4e 20 41 43 |WHETHER |IN AN AC|
|00000590| 54 49 4f 4e 20 4f 46 0a | 43 4f 4e 54 52 41 43 54 |TION OF.|CONTRACT|
|000005a0| 2c 20 4e 45 47 4c 49 47 | 45 4e 43 45 20 4f 52 20 |, NEGLIG|ENCE OR |
|000005b0| 4f 54 48 45 52 20 54 4f | 52 54 49 4f 55 53 20 41 |OTHER TO|RTIOUS A|
|000005c0| 43 54 49 4f 4e 2c 20 41 | 52 49 53 49 4e 47 20 4f |CTION, A|RISING O|
|000005d0| 55 54 20 4f 46 20 4f 52 | 20 49 4e 0a 43 4f 4e 4e |UT OF OR| IN.CONN|
|000005e0| 45 43 54 49 4f 4e 20 57 | 49 54 48 20 54 48 45 20 |ECTION W|ITH THE |
|000005f0| 55 53 45 20 4f 52 20 50 | 45 52 46 4f 52 4d 41 4e |USE OR P|ERFORMAN|
|00000600| 43 45 20 4f 46 20 54 48 | 49 53 20 53 4f 46 54 57 |CE OF TH|IS SOFTW|
|00000610| 41 52 45 2e 0a 0a 0a 54 | 68 65 20 70 72 6f 66 69 |ARE....T|he profi|
|00000620| 6c 65 72 20 77 61 73 20 | 77 72 69 74 74 65 6e 20 |ler was |written |
|00000630| 61 66 74 65 72 20 6f 6e | 6c 79 20 70 72 6f 67 72 |after on|ly progr|
|00000640| 61 6d 6d 69 6e 67 20 69 | 6e 20 50 79 74 68 6f 6e |amming i|n Python|
|00000650| 20 66 6f 72 20 33 20 77 | 65 65 6b 73 2e 0a 41 73 | for 3 w|eeks..As|
|00000660| 20 61 20 72 65 73 75 6c | 74 2c 20 69 74 20 69 73 | a resul|t, it is|
|00000670| 20 70 72 6f 62 61 62 6c | 79 20 63 6c 75 6d 73 79 | probabl|y clumsy|
|00000680| 20 63 6f 64 65 2c 20 62 | 75 74 20 49 20 64 6f 6e | code, b|ut I don|
|00000690| 27 74 20 6b 6e 6f 77 20 | 66 6f 72 20 73 75 72 65 |'t know |for sure|
|000006a0| 20 79 65 74 0a 27 63 61 | 75 73 65 20 49 27 6d 20 | yet.'ca|use I'm |
|000006b0| 61 20 62 65 67 69 6e 6e | 65 72 20 3a 2d 29 2e 20 |a beginn|er :-). |
|000006c0| 20 49 20 64 69 64 20 77 | 6f 72 6b 20 68 61 72 64 | I did w|ork hard|
|000006d0| 20 74 6f 20 6d 61 6b 65 | 20 74 68 65 20 63 6f 64 | to make| the cod|
|000006e0| 65 20 72 75 6e 20 66 61 | 73 74 2c 0a 73 6f 20 74 |e run fa|st,.so t|
|000006f0| 68 61 74 20 70 72 6f 66 | 69 6c 69 6e 67 20 77 6f |hat prof|iling wo|
|00000700| 75 6c 64 20 62 65 20 61 | 20 72 65 61 73 6f 6e 61 |uld be a| reasona|
|00000710| 62 6c 65 20 74 68 69 6e | 67 20 74 6f 20 64 6f 2e |ble thin|g to do.|
|00000720| 20 20 49 20 74 72 69 65 | 64 20 6e 6f 74 20 74 6f | I trie|d not to|
|00000730| 0a 72 65 70 65 61 74 20 | 63 6f 64 65 20 66 72 61 |.repeat |code fra|
|00000740| 67 6d 65 6e 74 73 2c 20 | 62 75 74 20 49 27 6d 20 |gments, |but I'm |
|00000750| 73 75 72 65 20 49 20 64 | 69 64 20 73 6f 6d 65 20 |sure I d|id some |
|00000760| 73 74 75 66 66 20 69 6e | 20 72 65 61 6c 6c 79 20 |stuff in| really |
|00000770| 61 77 6b 77 61 72 64 0a | 77 61 79 73 20 61 74 20 |awkward.|ways at |
|00000780| 74 69 6d 65 73 2e 20 20 | 50 6c 65 61 73 65 20 73 |times. |Please s|
|00000790| 65 6e 64 20 73 75 67 67 | 65 73 74 69 6f 6e 73 20 |end sugg|estions |
|000007a0| 66 6f 72 20 69 6d 70 72 | 6f 76 65 6d 65 6e 74 73 |for impr|ovements|
|000007b0| 20 74 6f 3a 0a 5c 63 6f | 64 65 7b 6a 61 72 40 6e | to:.\co|de{jar@n|
|000007c0| 65 74 73 63 61 70 65 2e | 63 6f 6d 7d 2e 20 20 49 |etscape.|com}. I|
|000007d0| 20 77 6f 6e 27 74 20 70 | 72 6f 6d 69 73 65 20 5c | won't p|romise \|
|000007e0| 65 6d 70 68 7b 61 6e 79 | 7d 20 73 75 70 70 6f 72 |emph{any|} suppor|
|000007f0| 74 2e 20 20 2e 2e 2e 62 | 75 74 0a 49 27 64 20 61 |t. ...b|ut.I'd a|
|00000800| 70 70 72 65 63 69 61 74 | 65 20 74 68 65 20 66 65 |ppreciat|e the fe|
|00000810| 65 64 62 61 63 6b 2e 0a | 0a 0a 5c 73 65 63 74 69 |edback..|..\secti|
|00000820| 6f 6e 7b 49 6e 74 72 6f | 64 75 63 74 69 6f 6e 20 |on{Intro|duction |
|00000830| 74 6f 20 74 68 65 20 70 | 72 6f 66 69 6c 65 72 7d |to the p|rofiler}|
|00000840| 0a 5c 6e 6f 64 65 6e 61 | 6d 65 7b 50 72 6f 66 69 |.\nodena|me{Profi|
|00000850| 6c 65 72 20 49 6e 74 72 | 6f 64 75 63 74 69 6f 6e |ler Intr|oduction|
|00000860| 7d 0a 0a 41 20 5c 64 66 | 6e 7b 70 72 6f 66 69 6c |}..A \df|n{profil|
|00000870| 65 72 7d 20 69 73 20 61 | 20 70 72 6f 67 72 61 6d |er} is a| program|
|00000880| 20 74 68 61 74 20 64 65 | 73 63 72 69 62 65 73 20 | that de|scribes |
|00000890| 74 68 65 20 72 75 6e 20 | 74 69 6d 65 20 70 65 72 |the run |time per|
|000008a0| 66 6f 72 6d 61 6e 63 65 | 0a 6f 66 20 61 20 70 72 |formance|.of a pr|
|000008b0| 6f 67 72 61 6d 2c 20 70 | 72 6f 76 69 64 69 6e 67 |ogram, p|roviding|
|000008c0| 20 61 20 76 61 72 69 65 | 74 79 20 6f 66 20 73 74 | a varie|ty of st|
|000008d0| 61 74 69 73 74 69 63 73 | 2e 20 20 54 68 69 73 20 |atistics|. This |
|000008e0| 64 6f 63 75 6d 65 6e 74 | 61 74 69 6f 6e 0a 64 65 |document|ation.de|
|000008f0| 73 63 72 69 62 65 73 20 | 74 68 65 20 70 72 6f 66 |scribes |the prof|
|00000900| 69 6c 65 72 20 66 75 6e | 63 74 69 6f 6e 61 6c 69 |iler fun|ctionali|
|00000910| 74 79 20 70 72 6f 76 69 | 64 65 64 20 69 6e 20 74 |ty provi|ded in t|
|00000920| 68 65 20 6d 6f 64 75 6c | 65 73 0a 5c 63 6f 64 65 |he modul|es.\code|
|00000930| 7b 70 72 6f 66 69 6c 65 | 7d 20 61 6e 64 20 5c 63 |{profile|} and \c|
|00000940| 6f 64 65 7b 70 73 74 61 | 74 73 2e 7d 20 20 54 68 |ode{psta|ts.} Th|
|00000950| 69 73 20 70 72 6f 66 69 | 6c 65 72 20 70 72 6f 76 |is profi|ler prov|
|00000960| 69 64 65 73 0a 5c 64 66 | 6e 7b 64 65 74 65 72 6d |ides.\df|n{determ|
|00000970| 69 6e 69 73 74 69 63 20 | 70 72 6f 66 69 6c 69 6e |inistic |profilin|
|00000980| 67 7d 20 6f 66 20 61 6e | 79 20 50 79 74 68 6f 6e |g} of an|y Python|
|00000990| 20 70 72 6f 67 72 61 6d | 73 2e 20 20 49 74 20 61 | program|s. It a|
|000009a0| 6c 73 6f 0a 70 72 6f 76 | 69 64 65 73 20 61 20 73 |lso.prov|ides a s|
|000009b0| 65 72 69 65 73 20 6f 66 | 20 72 65 70 6f 72 74 20 |eries of| report |
|000009c0| 67 65 6e 65 72 61 74 69 | 6f 6e 20 74 6f 6f 6c 73 |generati|on tools|
|000009d0| 20 74 6f 20 61 6c 6c 6f | 77 20 75 73 65 72 73 20 | to allo|w users |
|000009e0| 74 6f 20 72 61 70 69 64 | 6c 79 0a 65 78 61 6d 69 |to rapid|ly.exami|
|000009f0| 6e 65 20 74 68 65 20 72 | 65 73 75 6c 74 73 20 6f |ne the r|esults o|
|00000a00| 66 20 61 20 70 72 6f 66 | 69 6c 65 20 6f 70 65 72 |f a prof|ile oper|
|00000a10| 61 74 69 6f 6e 2e 0a 0a | 0a 5c 73 65 63 74 69 6f |ation...|.\sectio|
|00000a20| 6e 7b 48 6f 77 20 49 73 | 20 54 68 69 73 20 50 72 |n{How Is| This Pr|
|00000a30| 6f 66 69 6c 65 72 20 44 | 69 66 66 65 72 65 6e 74 |ofiler D|ifferent|
|00000a40| 20 46 72 6f 6d 20 54 68 | 65 20 4f 6c 64 20 50 72 | From Th|e Old Pr|
|00000a50| 6f 66 69 6c 65 72 3f 7d | 0a 5c 6e 6f 64 65 6e 61 |ofiler?}|.\nodena|
|00000a60| 6d 65 7b 50 72 6f 66 69 | 6c 65 72 20 43 68 61 6e |me{Profi|ler Chan|
|00000a70| 67 65 73 7d 0a 0a 54 68 | 65 20 62 69 67 20 63 68 |ges}..Th|e big ch|
|00000a80| 61 6e 67 65 73 20 66 72 | 6f 6d 20 6f 6c 64 20 70 |anges fr|om old p|
|00000a90| 72 6f 66 69 6c 69 6e 67 | 20 6d 6f 64 75 6c 65 20 |rofiling| module |
|00000aa0| 61 72 65 20 74 68 61 74 | 20 79 6f 75 20 67 65 74 |are that| you get|
|00000ab0| 20 6d 6f 72 65 0a 69 6e | 66 6f 72 6d 61 74 69 6f | more.in|formatio|
|00000ac0| 6e 2c 20 61 6e 64 20 79 | 6f 75 20 70 61 79 20 6c |n, and y|ou pay l|
|00000ad0| 65 73 73 20 43 50 55 20 | 74 69 6d 65 2e 20 20 49 |ess CPU |time. I|
|00000ae0| 74 27 73 20 6e 6f 74 20 | 61 20 74 72 61 64 65 2d |t's not |a trade-|
|00000af0| 6f 66 66 2c 20 69 74 27 | 73 20 61 0a 74 72 61 64 |off, it'|s a.trad|
|00000b00| 65 2d 75 70 2e 0a 0a 54 | 6f 20 62 65 20 73 70 65 |e-up...T|o be spe|
|00000b10| 63 69 66 69 63 3a 0a 0a | 5c 62 65 67 69 6e 7b 64 |cific:..|\begin{d|
|00000b20| 65 73 63 72 69 70 74 69 | 6f 6e 7d 0a 0a 5c 69 74 |escripti|on}..\it|
|00000b30| 65 6d 5b 42 75 67 73 20 | 72 65 6d 6f 76 65 64 3a |em[Bugs |removed:|
|00000b40| 5d 0a 4c 6f 63 61 6c 20 | 73 74 61 63 6b 20 66 72 |].Local |stack fr|
|00000b50| 61 6d 65 20 69 73 20 6e | 6f 20 6c 6f 6e 67 65 72 |ame is n|o longer|
|00000b60| 20 6d 6f 6c 65 73 74 65 | 64 2c 20 65 78 65 63 75 | moleste|d, execu|
|00000b70| 74 69 6f 6e 20 74 69 6d | 65 20 69 73 20 6e 6f 77 |tion tim|e is now|
|00000b80| 20 63 68 61 72 67 65 64 | 0a 74 6f 20 63 6f 72 72 | charged|.to corr|
|00000b90| 65 63 74 20 66 75 6e 63 | 74 69 6f 6e 73 2e 0a 0a |ect func|tions...|
|00000ba0| 5c 69 74 65 6d 5b 41 63 | 63 75 72 61 63 79 20 69 |\item[Ac|curacy i|
|00000bb0| 6e 63 72 65 61 73 65 64 | 3a 5d 0a 50 72 6f 66 69 |ncreased|:].Profi|
|00000bc0| 6c 65 72 20 65 78 65 63 | 75 74 69 6f 6e 20 74 69 |ler exec|ution ti|
|00000bd0| 6d 65 20 69 73 20 6e 6f | 20 6c 6f 6e 67 65 72 20 |me is no| longer |
|00000be0| 63 68 61 72 67 65 64 20 | 74 6f 20 75 73 65 72 27 |charged |to user'|
|00000bf0| 73 20 63 6f 64 65 2c 0a | 63 61 6c 69 62 72 61 74 |s code,.|calibrat|
|00000c00| 69 6f 6e 20 66 6f 72 20 | 70 6c 61 74 66 6f 72 6d |ion for |platform|
|00000c10| 20 69 73 20 73 75 70 70 | 6f 72 74 65 64 2c 20 66 | is supp|orted, f|
|00000c20| 69 6c 65 20 72 65 61 64 | 73 20 61 72 65 20 6e 6f |ile read|s are no|
|00000c30| 74 20 64 6f 6e 65 20 5c | 65 6d 70 68 7b 62 79 7d |t done \|emph{by}|
|00000c40| 0a 70 72 6f 66 69 6c 65 | 72 20 5c 65 6d 70 68 7b |.profile|r \emph{|
|00000c50| 64 75 72 69 6e 67 7d 20 | 70 72 6f 66 69 6c 69 6e |during} |profilin|
|00000c60| 67 20 28 61 6e 64 20 63 | 68 61 72 67 65 64 20 74 |g (and c|harged t|
|00000c70| 6f 20 75 73 65 72 27 73 | 20 63 6f 64 65 21 29 2e |o user's| code!).|
|00000c80| 0a 0a 5c 69 74 65 6d 5b | 53 70 65 65 64 20 69 6e |..\item[|Speed in|
|00000c90| 63 72 65 61 73 65 64 3a | 5d 0a 4f 76 65 72 68 65 |creased:|].Overhe|
|00000ca0| 61 64 20 43 50 55 20 63 | 6f 73 74 20 77 61 73 20 |ad CPU c|ost was |
|00000cb0| 72 65 64 75 63 65 64 20 | 62 79 20 6d 6f 72 65 20 |reduced |by more |
|00000cc0| 74 68 61 6e 20 61 20 66 | 61 63 74 6f 72 20 6f 66 |than a f|actor of|
|00000cd0| 20 74 77 6f 20 28 70 65 | 72 68 61 70 73 20 61 0a | two (pe|rhaps a.|
|00000ce0| 66 61 63 74 6f 72 20 6f | 66 20 66 69 76 65 29 2c |factor o|f five),|
|00000cf0| 20 6c 69 67 68 74 77 65 | 69 67 68 74 20 70 72 6f | lightwe|ight pro|
|00000d00| 66 69 6c 65 72 20 6d 6f | 64 75 6c 65 20 69 73 20 |filer mo|dule is |
|00000d10| 61 6c 6c 20 74 68 61 74 | 20 6d 75 73 74 20 62 65 |all that| must be|
|00000d20| 0a 6c 6f 61 64 65 64 2c | 20 61 6e 64 20 74 68 65 |.loaded,| and the|
|00000d30| 20 72 65 70 6f 72 74 20 | 67 65 6e 65 72 61 74 69 | report |generati|
|00000d40| 6e 67 20 6d 6f 64 75 6c | 65 20 28 5c 63 6f 64 65 |ng modul|e (\code|
|00000d50| 7b 70 73 74 61 74 73 7d | 29 20 69 73 20 6e 6f 74 |{pstats}|) is not|
|00000d60| 20 6e 65 65 64 65 64 0a | 64 75 72 69 6e 67 20 70 | needed.|during p|
|00000d70| 72 6f 66 69 6c 69 6e 67 | 2e 0a 0a 5c 69 74 65 6d |rofiling|...\item|
|00000d80| 5b 52 65 63 75 72 73 69 | 76 65 20 66 75 6e 63 74 |[Recursi|ve funct|
|00000d90| 69 6f 6e 73 20 73 75 70 | 70 6f 72 74 3a 5d 0a 43 |ions sup|port:].C|
|00000da0| 75 6d 75 6c 61 74 69 76 | 65 20 74 69 6d 65 73 20 |umulativ|e times |
|00000db0| 69 6e 20 72 65 63 75 72 | 73 69 76 65 20 66 75 6e |in recur|sive fun|
|00000dc0| 63 74 69 6f 6e 73 20 61 | 72 65 20 63 6f 72 72 65 |ctions a|re corre|
|00000dd0| 63 74 6c 79 20 63 61 6c | 63 75 6c 61 74 65 64 3b |ctly cal|culated;|
|00000de0| 0a 72 65 63 75 72 73 69 | 76 65 20 65 6e 74 72 69 |.recursi|ve entri|
|00000df0| 65 73 20 61 72 65 20 63 | 6f 75 6e 74 65 64 2e 0a |es are c|ounted..|
|00000e00| 0a 5c 69 74 65 6d 5b 4c | 61 72 67 65 20 67 72 6f |.\item[L|arge gro|
|00000e10| 77 74 68 20 69 6e 20 72 | 65 70 6f 72 74 20 67 65 |wth in r|eport ge|
|00000e20| 6e 65 72 61 74 69 6e 67 | 20 55 49 3a 5d 0a 44 69 |nerating| UI:].Di|
|00000e30| 73 74 69 6e 63 74 20 70 | 72 6f 66 69 6c 65 73 20 |stinct p|rofiles |
|00000e40| 72 75 6e 73 20 63 61 6e | 20 62 65 20 61 64 64 65 |runs can| be adde|
|00000e50| 64 20 74 6f 67 65 74 68 | 65 72 20 66 6f 72 6d 69 |d togeth|er formi|
|00000e60| 6e 67 20 61 20 63 6f 6d | 70 72 65 68 65 6e 73 69 |ng a com|prehensi|
|00000e70| 76 65 0a 72 65 70 6f 72 | 74 3b 20 66 75 6e 63 74 |ve.repor|t; funct|
|00000e80| 69 6f 6e 73 20 74 68 61 | 74 20 69 6d 70 6f 72 74 |ions tha|t import|
|00000e90| 20 73 74 61 74 69 73 74 | 69 63 73 20 74 61 6b 65 | statist|ics take|
|00000ea0| 20 61 72 62 69 74 72 61 | 72 79 20 6c 69 73 74 73 | arbitra|ry lists|
|00000eb0| 20 6f 66 0a 66 69 6c 65 | 73 3b 20 73 6f 72 74 69 | of.file|s; sorti|
|00000ec0| 6e 67 20 63 72 69 74 65 | 72 69 61 20 69 73 20 6e |ng crite|ria is n|
|00000ed0| 6f 77 20 62 61 73 65 64 | 20 6f 6e 20 6b 65 79 77 |ow based| on keyw|
|00000ee0| 6f 72 64 73 20 28 69 6e | 73 74 65 61 64 20 6f 66 |ords (in|stead of|
|00000ef0| 20 34 20 69 6e 74 65 67 | 65 72 0a 6f 70 74 69 6f | 4 integ|er.optio|
|00000f00| 6e 73 29 3b 20 72 65 70 | 6f 72 74 73 20 73 68 6f |ns); rep|orts sho|
|00000f10| 77 73 20 77 68 61 74 20 | 66 75 6e 63 74 69 6f 6e |ws what |function|
|00000f20| 73 20 77 65 72 65 20 70 | 72 6f 66 69 6c 65 64 20 |s were p|rofiled |
|00000f30| 61 73 20 77 65 6c 6c 20 | 61 73 20 77 68 61 74 0a |as well |as what.|
|00000f40| 70 72 6f 66 69 6c 65 20 | 66 69 6c 65 20 77 61 73 |profile |file was|
|00000f50| 20 72 65 66 65 72 65 6e | 63 65 64 3b 20 6f 75 74 | referen|ced; out|
|00000f60| 70 75 74 20 66 6f 72 6d | 61 74 20 68 61 73 20 62 |put form|at has b|
|00000f70| 65 65 6e 20 69 6d 70 72 | 6f 76 65 64 2e 0a 0a 5c |een impr|oved...\|
|00000f80| 65 6e 64 7b 64 65 73 63 | 72 69 70 74 69 6f 6e 7d |end{desc|ription}|
|00000f90| 0a 0a 0a 5c 73 65 63 74 | 69 6f 6e 7b 49 6e 73 74 |...\sect|ion{Inst|
|00000fa0| 61 6e 74 20 55 73 65 72 | 73 20 4d 61 6e 75 61 6c |ant User|s Manual|
|00000fb0| 7d 0a 0a 54 68 69 73 20 | 73 65 63 74 69 6f 6e 20 |}..This |section |
|00000fc0| 69 73 20 70 72 6f 76 69 | 64 65 64 20 66 6f 72 20 |is provi|ded for |
|00000fd0| 75 73 65 72 73 20 74 68 | 61 74 20 60 60 64 6f 6e |users th|at ``don|
|00000fe0| 27 74 20 77 61 6e 74 20 | 74 6f 20 72 65 61 64 20 |'t want |to read |
|00000ff0| 74 68 65 0a 6d 61 6e 75 | 61 6c 2e 27 27 20 49 74 |the.manu|al.'' It|
|00001000| 20 70 72 6f 76 69 64 65 | 73 20 61 20 76 65 72 79 | provide|s a very|
|00001010| 20 62 72 69 65 66 20 6f | 76 65 72 76 69 65 77 2c | brief o|verview,|
|00001020| 20 61 6e 64 20 61 6c 6c | 6f 77 73 20 61 20 75 73 | and all|ows a us|
|00001030| 65 72 20 74 6f 0a 72 61 | 70 69 64 6c 79 20 70 65 |er to.ra|pidly pe|
|00001040| 72 66 6f 72 6d 20 70 72 | 6f 66 69 6c 69 6e 67 20 |rform pr|ofiling |
|00001050| 6f 6e 20 61 6e 20 65 78 | 69 73 74 69 6e 67 20 61 |on an ex|isting a|
|00001060| 70 70 6c 69 63 61 74 69 | 6f 6e 2e 0a 0a 54 6f 20 |pplicati|on...To |
|00001070| 70 72 6f 66 69 6c 65 20 | 61 6e 20 61 70 70 6c 69 |profile |an appli|
|00001080| 63 61 74 69 6f 6e 20 77 | 69 74 68 20 61 20 6d 61 |cation w|ith a ma|
|00001090| 69 6e 20 65 6e 74 72 79 | 20 70 6f 69 6e 74 20 6f |in entry| point o|
|000010a0| 66 20 5c 73 61 6d 70 7b | 66 6f 6f 28 29 7d 2c 20 |f \samp{|foo()}, |
|000010b0| 79 6f 75 0a 77 6f 75 6c | 64 20 61 64 64 20 74 68 |you.woul|d add th|
|000010c0| 65 20 66 6f 6c 6c 6f 77 | 69 6e 67 20 74 6f 20 79 |e follow|ing to y|
|000010d0| 6f 75 72 20 6d 6f 64 75 | 6c 65 3a 0a 0a 5c 62 65 |our modu|le:..\be|
|000010e0| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0a 20 20 |gin{verb|atim}. |
|000010f0| 20 20 69 6d 70 6f 72 74 | 20 70 72 6f 66 69 6c 65 | import| profile|
|00001100| 0a 20 20 20 20 70 72 6f | 66 69 6c 65 2e 72 75 6e |. pro|file.run|
|00001110| 28 22 66 6f 6f 28 29 22 | 29 0a 5c 65 6e 64 7b 76 |("foo()"|).\end{v|
|00001120| 65 72 62 61 74 69 6d 7d | 0a 0a 54 68 65 20 61 62 |erbatim}|..The ab|
|00001130| 6f 76 65 20 61 63 74 69 | 6f 6e 20 77 6f 75 6c 64 |ove acti|on would|
|00001140| 20 63 61 75 73 65 20 5c | 73 61 6d 70 7b 66 6f 6f | cause \|samp{foo|
|00001150| 28 29 7d 20 74 6f 20 62 | 65 20 72 75 6e 2c 20 61 |()} to b|e run, a|
|00001160| 6e 64 20 61 20 73 65 72 | 69 65 73 20 6f 66 0a 69 |nd a ser|ies of.i|
|00001170| 6e 66 6f 72 6d 61 74 69 | 76 65 20 6c 69 6e 65 73 |nformati|ve lines|
|00001180| 20 28 74 68 65 20 70 72 | 6f 66 69 6c 65 29 20 74 | (the pr|ofile) t|
|00001190| 6f 20 62 65 20 70 72 69 | 6e 74 65 64 2e 20 20 54 |o be pri|nted. T|
|000011a0| 68 65 20 61 62 6f 76 65 | 20 61 70 70 72 6f 61 63 |he above| approac|
|000011b0| 68 20 69 73 0a 6d 6f 73 | 74 20 75 73 65 66 75 6c |h is.mos|t useful|
|000011c0| 20 77 68 65 6e 20 77 6f | 72 6b 69 6e 67 20 77 69 | when wo|rking wi|
|000011d0| 74 68 20 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |th the i|nterpret|
|000011e0| 65 72 2e 20 20 49 66 20 | 79 6f 75 20 77 6f 75 6c |er. If |you woul|
|000011f0| 64 20 6c 69 6b 65 20 74 | 6f 0a 73 61 76 65 20 74 |d like t|o.save t|
|00001200| 68 65 20 72 65 73 75 6c | 74 73 20 6f 66 20 61 20 |he resul|ts of a |
|00001210| 70 72 6f 66 69 6c 65 20 | 69 6e 74 6f 20 61 20 66 |profile |into a f|
|00001220| 69 6c 65 20 66 6f 72 20 | 6c 61 74 65 72 20 65 78 |ile for |later ex|
|00001230| 61 6d 69 6e 61 74 69 6f | 6e 2c 20 79 6f 75 0a 63 |aminatio|n, you.c|
|00001240| 61 6e 20 73 75 70 70 6c | 79 20 61 20 66 69 6c 65 |an suppl|y a file|
|00001250| 20 6e 61 6d 65 20 61 73 | 20 74 68 65 20 73 65 63 | name as| the sec|
|00001260| 6f 6e 64 20 61 72 67 75 | 6d 65 6e 74 20 74 6f 20 |ond argu|ment to |
|00001270| 74 68 65 20 5c 63 6f 64 | 65 7b 72 75 6e 28 29 7d |the \cod|e{run()}|
|00001280| 0a 66 75 6e 63 74 69 6f | 6e 3a 0a 0a 5c 62 65 67 |.functio|n:..\beg|
|00001290| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|000012a0| 20 69 6d 70 6f 72 74 20 | 70 72 6f 66 69 6c 65 0a | import |profile.|
|000012b0| 20 20 20 20 70 72 6f 66 | 69 6c 65 2e 72 75 6e 28 | prof|ile.run(|
|000012c0| 22 66 6f 6f 28 29 22 2c | 20 27 66 6f 6f 70 72 6f |"foo()",| 'foopro|
|000012d0| 66 27 29 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |f').\end|{verbati|
|000012e0| 6d 7d 0a 0a 57 68 65 6e | 20 79 6f 75 20 77 69 73 |m}..When| you wis|
|000012f0| 68 20 74 6f 20 72 65 76 | 69 65 77 20 74 68 65 20 |h to rev|iew the |
|00001300| 70 72 6f 66 69 6c 65 2c | 20 79 6f 75 20 73 68 6f |profile,| you sho|
|00001310| 75 6c 64 20 75 73 65 20 | 74 68 65 20 6d 65 74 68 |uld use |the meth|
|00001320| 6f 64 73 20 69 6e 20 74 | 68 65 0a 5c 63 6f 64 65 |ods in t|he.\code|
|00001330| 7b 70 73 74 61 74 73 7d | 20 6d 6f 64 75 6c 65 2e |{pstats}| module.|
|00001340| 20 20 54 79 70 69 63 61 | 6c 6c 79 20 79 6f 75 20 | Typica|lly you |
|00001350| 77 6f 75 6c 64 20 6c 6f | 61 64 20 74 68 65 20 73 |would lo|ad the s|
|00001360| 74 61 74 69 73 74 69 63 | 73 20 64 61 74 61 20 61 |tatistic|s data a|
|00001370| 73 0a 66 6f 6c 6c 6f 77 | 73 3a 0a 0a 5c 62 65 67 |s.follow|s:..\beg|
|00001380| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|00001390| 20 69 6d 70 6f 72 74 20 | 70 73 74 61 74 73 0a 20 | import |pstats. |
|000013a0| 20 20 20 70 20 3d 20 70 | 73 74 61 74 73 2e 53 74 | p = p|stats.St|
|000013b0| 61 74 73 28 27 66 6f 6f | 70 72 6f 66 27 29 0a 5c |ats('foo|prof').\|
|000013c0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 0a 54 |end{verb|atim}..T|
|000013d0| 68 65 20 63 6c 61 73 73 | 20 5c 63 6f 64 65 7b 53 |he class| \code{S|
|000013e0| 74 61 74 73 7d 20 28 74 | 68 65 20 61 62 6f 76 65 |tats} (t|he above|
|000013f0| 20 63 6f 64 65 20 6a 75 | 73 74 20 63 72 65 61 74 | code ju|st creat|
|00001400| 65 64 20 61 6e 20 69 6e | 73 74 61 6e 63 65 20 6f |ed an in|stance o|
|00001410| 66 0a 74 68 69 73 20 63 | 6c 61 73 73 29 20 68 61 |f.this c|lass) ha|
|00001420| 73 20 61 20 76 61 72 69 | 65 74 79 20 6f 66 20 6d |s a vari|ety of m|
|00001430| 65 74 68 6f 64 73 20 66 | 6f 72 20 6d 61 6e 69 70 |ethods f|or manip|
|00001440| 75 6c 61 74 69 6e 67 20 | 61 6e 64 20 70 72 69 6e |ulating |and prin|
|00001450| 74 69 6e 67 20 74 68 65 | 0a 64 61 74 61 20 74 68 |ting the|.data th|
|00001460| 61 74 20 77 61 73 20 6a | 75 73 74 20 72 65 61 64 |at was j|ust read|
|00001470| 20 69 6e 74 6f 20 5c 73 | 61 6d 70 7b 70 7d 2e 20 | into \s|amp{p}. |
|00001480| 20 57 68 65 6e 20 79 6f | 75 20 72 61 6e 0a 5c 63 | When yo|u ran.\c|
|00001490| 6f 64 65 7b 70 72 6f 66 | 69 6c 65 2e 72 75 6e 28 |ode{prof|ile.run(|
|000014a0| 29 7d 20 61 62 6f 76 65 | 2c 20 77 68 61 74 20 77 |)} above|, what w|
|000014b0| 61 73 20 70 72 69 6e 74 | 65 64 20 77 61 73 20 74 |as print|ed was t|
|000014c0| 68 65 20 72 65 73 75 6c | 74 20 6f 66 20 74 68 72 |he resul|t of thr|
|000014d0| 65 65 0a 6d 65 74 68 6f | 64 20 63 61 6c 6c 73 3a |ee.metho|d calls:|
|000014e0| 0a 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |..\begin|{verbati|
|000014f0| 6d 7d 0a 20 20 20 20 70 | 2e 73 74 72 69 70 5f 64 |m}. p|.strip_d|
|00001500| 69 72 73 28 29 2e 73 6f | 72 74 5f 73 74 61 74 73 |irs().so|rt_stats|
|00001510| 28 2d 31 29 2e 70 72 69 | 6e 74 5f 73 74 61 74 73 |(-1).pri|nt_stats|
|00001520| 28 29 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |().\end{|verbatim|
|00001530| 7d 0a 0a 54 68 65 20 66 | 69 72 73 74 20 6d 65 74 |}..The f|irst met|
|00001540| 68 6f 64 20 72 65 6d 6f | 76 65 64 20 74 68 65 20 |hod remo|ved the |
|00001550| 65 78 74 72 61 6e 65 6f | 75 73 20 70 61 74 68 20 |extraneo|us path |
|00001560| 66 72 6f 6d 20 61 6c 6c | 20 74 68 65 20 6d 6f 64 |from all| the mod|
|00001570| 75 6c 65 0a 6e 61 6d 65 | 73 2e 20 54 68 65 20 73 |ule.name|s. The s|
|00001580| 65 63 6f 6e 64 20 6d 65 | 74 68 6f 64 20 73 6f 72 |econd me|thod sor|
|00001590| 74 65 64 20 61 6c 6c 20 | 74 68 65 20 65 6e 74 72 |ted all |the entr|
|000015a0| 69 65 73 20 61 63 63 6f | 72 64 69 6e 67 20 74 6f |ies acco|rding to|
|000015b0| 20 74 68 65 0a 73 74 61 | 6e 64 61 72 64 20 6d 6f | the.sta|ndard mo|
|000015c0| 64 75 6c 65 2f 6c 69 6e | 65 2f 6e 61 6d 65 20 73 |dule/lin|e/name s|
|000015d0| 74 72 69 6e 67 20 74 68 | 61 74 20 69 73 20 70 72 |tring th|at is pr|
|000015e0| 69 6e 74 65 64 20 28 74 | 68 69 73 20 69 73 20 74 |inted (t|his is t|
|000015f0| 6f 20 63 6f 6d 70 6c 79 | 0a 77 69 74 68 20 74 68 |o comply|.with th|
|00001600| 65 20 73 65 6d 61 6e 74 | 69 63 73 20 6f 66 20 74 |e semant|ics of t|
|00001610| 68 65 20 6f 6c 64 20 70 | 72 6f 66 69 6c 65 72 29 |he old p|rofiler)|
|00001620| 2e 20 20 54 68 65 20 74 | 68 69 72 64 20 6d 65 74 |. The t|hird met|
|00001630| 68 6f 64 20 70 72 69 6e | 74 65 64 20 6f 75 74 0a |hod prin|ted out.|
|00001640| 61 6c 6c 20 74 68 65 20 | 73 74 61 74 69 73 74 69 |all the |statisti|
|00001650| 63 73 2e 20 20 59 6f 75 | 20 6d 69 67 68 74 20 74 |cs. You| might t|
|00001660| 72 79 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |ry the f|ollowing|
|00001670| 20 73 6f 72 74 20 63 61 | 6c 6c 73 3a 0a 0a 5c 62 | sort ca|lls:..\b|
|00001680| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 20 |egin{ver|batim}. |
|00001690| 20 20 20 70 2e 73 6f 72 | 74 5f 73 74 61 74 73 28 | p.sor|t_stats(|
|000016a0| 27 6e 61 6d 65 27 29 0a | 20 20 20 20 70 2e 70 72 |'name').| p.pr|
|000016b0| 69 6e 74 5f 73 74 61 74 | 73 28 29 0a 5c 65 6e 64 |int_stat|s().\end|
|000016c0| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 0a 54 68 65 20 |{verbati|m}..The |
|000016d0| 66 69 72 73 74 20 63 61 | 6c 6c 20 77 69 6c 6c 20 |first ca|ll will |
|000016e0| 61 63 74 75 61 6c 6c 79 | 20 73 6f 72 74 20 74 68 |actually| sort th|
|000016f0| 65 20 6c 69 73 74 20 62 | 79 20 66 75 6e 63 74 69 |e list b|y functi|
|00001700| 6f 6e 20 6e 61 6d 65 2c | 20 61 6e 64 20 74 68 65 |on name,| and the|
|00001710| 0a 73 65 63 6f 6e 64 20 | 63 61 6c 6c 20 77 69 6c |.second |call wil|
|00001720| 6c 20 70 72 69 6e 74 20 | 6f 75 74 20 74 68 65 20 |l print |out the |
|00001730| 73 74 61 74 69 73 74 69 | 63 73 2e 20 20 54 68 65 |statisti|cs. The|
|00001740| 20 66 6f 6c 6c 6f 77 69 | 6e 67 20 61 72 65 20 73 | followi|ng are s|
|00001750| 6f 6d 65 0a 69 6e 74 65 | 72 65 73 74 69 6e 67 20 |ome.inte|resting |
|00001760| 63 61 6c 6c 73 20 74 6f | 20 65 78 70 65 72 69 6d |calls to| experim|
|00001770| 65 6e 74 20 77 69 74 68 | 3a 0a 0a 5c 62 65 67 69 |ent with|:..\begi|
|00001780| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0a 20 20 20 20 |n{verbat|im}. |
|00001790| 70 2e 73 6f 72 74 5f 73 | 74 61 74 73 28 27 63 75 |p.sort_s|tats('cu|
|000017a0| 6d 75 6c 61 74 69 76 65 | 27 29 2e 70 72 69 6e 74 |mulative|').print|
|000017b0| 5f 73 74 61 74 73 28 31 | 30 29 0a 5c 65 6e 64 7b |_stats(1|0).\end{|
|000017c0| 76 65 72 62 61 74 69 6d | 7d 0a 0a 54 68 69 73 20 |verbatim|}..This |
|000017d0| 73 6f 72 74 73 20 74 68 | 65 20 70 72 6f 66 69 6c |sorts th|e profil|
|000017e0| 65 20 62 79 20 63 75 6d | 75 6c 61 74 69 76 65 20 |e by cum|ulative |
|000017f0| 74 69 6d 65 20 69 6e 20 | 61 20 66 75 6e 63 74 69 |time in |a functi|
|00001800| 6f 6e 2c 20 61 6e 64 20 | 74 68 65 6e 20 6f 6e 6c |on, and |then onl|
|00001810| 79 0a 70 72 69 6e 74 73 | 20 74 68 65 20 74 65 6e |y.prints| the ten|
|00001820| 20 6d 6f 73 74 20 73 69 | 67 6e 69 66 69 63 61 6e | most si|gnifican|
|00001830| 74 20 6c 69 6e 65 73 2e | 20 20 49 66 20 79 6f 75 |t lines.| If you|
|00001840| 20 77 61 6e 74 20 74 6f | 20 75 6e 64 65 72 73 74 | want to| underst|
|00001850| 61 6e 64 20 77 68 61 74 | 0a 61 6c 67 6f 72 69 74 |and what|.algorit|
|00001860| 68 6d 73 20 61 72 65 20 | 74 61 6b 69 6e 67 20 74 |hms are |taking t|
|00001870| 69 6d 65 2c 20 74 68 65 | 20 61 62 6f 76 65 20 6c |ime, the| above l|
|00001880| 69 6e 65 20 69 73 20 77 | 68 61 74 20 79 6f 75 20 |ine is w|hat you |
|00001890| 77 6f 75 6c 64 20 75 73 | 65 2e 0a 0a 49 66 20 79 |would us|e...If y|
|000018a0| 6f 75 20 77 65 72 65 20 | 6c 6f 6f 6b 69 6e 67 20 |ou were |looking |
|000018b0| 74 6f 20 73 65 65 20 77 | 68 61 74 20 66 75 6e 63 |to see w|hat func|
|000018c0| 74 69 6f 6e 73 20 77 65 | 72 65 20 6c 6f 6f 70 69 |tions we|re loopi|
|000018d0| 6e 67 20 61 20 6c 6f 74 | 2c 20 61 6e 64 0a 74 61 |ng a lot|, and.ta|
|000018e0| 6b 69 6e 67 20 61 20 6c | 6f 74 20 6f 66 20 74 69 |king a l|ot of ti|
|000018f0| 6d 65 2c 20 79 6f 75 20 | 77 6f 75 6c 64 20 64 6f |me, you |would do|
|00001900| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |:..\begi|n{verbat|
|00001910| 69 6d 7d 0a 20 20 20 20 | 70 2e 73 6f 72 74 5f 73 |im}. |p.sort_s|
|00001920| 74 61 74 73 28 27 74 69 | 6d 65 27 29 2e 70 72 69 |tats('ti|me').pri|
|00001930| 6e 74 5f 73 74 61 74 73 | 28 31 30 29 0a 5c 65 6e |nt_stats|(10).\en|
|00001940| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0a 0a 74 6f 20 |d{verbat|im}..to |
|00001950| 73 6f 72 74 20 61 63 63 | 6f 72 64 69 6e 67 20 74 |sort acc|ording t|
|00001960| 6f 20 74 69 6d 65 20 73 | 70 65 6e 74 20 77 69 74 |o time s|pent wit|
|00001970| 68 69 6e 20 65 61 63 68 | 20 66 75 6e 63 74 69 6f |hin each| functio|
|00001980| 6e 2c 20 61 6e 64 20 74 | 68 65 6e 20 70 72 69 6e |n, and t|hen prin|
|00001990| 74 0a 74 68 65 20 73 74 | 61 74 69 73 74 69 63 73 |t.the st|atistics|
|000019a0| 20 66 6f 72 20 74 68 65 | 20 74 6f 70 20 74 65 6e | for the| top ten|
|000019b0| 20 66 75 6e 63 74 69 6f | 6e 73 2e 0a 0a 59 6f 75 | functio|ns...You|
|000019c0| 20 6d 69 67 68 74 20 61 | 6c 73 6f 20 74 72 79 3a | might a|lso try:|
|000019d0| 0a 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |..\begin|{verbati|
|000019e0| 6d 7d 0a 20 20 20 20 70 | 2e 73 6f 72 74 5f 73 74 |m}. p|.sort_st|
|000019f0| 61 74 73 28 27 66 69 6c | 65 27 29 2e 70 72 69 6e |ats('fil|e').prin|
|00001a00| 74 5f 73 74 61 74 73 28 | 27 5f 5f 69 6e 69 74 5f |t_stats(|'__init_|
|00001a10| 5f 27 29 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |_').\end|{verbati|
|00001a20| 6d 7d 0a 0a 54 68 69 73 | 20 77 69 6c 6c 20 73 6f |m}..This| will so|
|00001a30| 72 74 20 61 6c 6c 20 74 | 68 65 20 73 74 61 74 69 |rt all t|he stati|
|00001a40| 73 74 69 63 73 20 62 79 | 20 66 69 6c 65 20 6e 61 |stics by| file na|
|00001a50| 6d 65 2c 20 61 6e 64 20 | 74 68 65 6e 20 70 72 69 |me, and |then pri|
|00001a60| 6e 74 20 6f 75 74 0a 73 | 74 61 74 69 73 74 69 63 |nt out.s|tatistic|
|00001a70| 73 20 66 6f 72 20 6f 6e | 6c 79 20 74 68 65 20 63 |s for on|ly the c|
|00001a80| 6c 61 73 73 20 69 6e 69 | 74 20 6d 65 74 68 6f 64 |lass ini|t method|
|00001a90| 73 20 28 27 63 61 75 73 | 65 20 74 68 65 79 20 61 |s ('caus|e they a|
|00001aa0| 72 65 20 73 70 65 6c 6c | 65 64 0a 77 69 74 68 20 |re spell|ed.with |
|00001ab0| 5c 63 6f 64 65 7b 5f 5f | 69 6e 69 74 5f 5f 7d 20 |\code{__|init__} |
|00001ac0| 69 6e 20 74 68 65 6d 29 | 2e 20 20 41 73 20 6f 6e |in them)|. As on|
|00001ad0| 65 20 66 69 6e 61 6c 20 | 65 78 61 6d 70 6c 65 2c |e final |example,|
|00001ae0| 20 79 6f 75 20 63 6f 75 | 6c 64 20 74 72 79 3a 0a | you cou|ld try:.|
|00001af0| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00001b00| 7d 0a 20 20 20 20 70 2e | 73 6f 72 74 5f 73 74 61 |}. p.|sort_sta|
|00001b10| 74 73 28 27 74 69 6d 65 | 27 2c 20 27 63 75 6d 27 |ts('time|', 'cum'|
|00001b20| 29 2e 70 72 69 6e 74 5f | 73 74 61 74 73 28 2e 35 |).print_|stats(.5|
|00001b30| 2c 20 27 69 6e 69 74 27 | 29 0a 5c 65 6e 64 7b 76 |, 'init'|).\end{v|
|00001b40| 65 72 62 61 74 69 6d 7d | 0a 0a 54 68 69 73 20 6c |erbatim}|..This l|
|00001b50| 69 6e 65 20 73 6f 72 74 | 73 20 73 74 61 74 69 73 |ine sort|s statis|
|00001b60| 74 69 63 73 20 77 69 74 | 68 20 61 20 70 72 69 6d |tics wit|h a prim|
|00001b70| 61 72 79 20 6b 65 79 20 | 6f 66 20 74 69 6d 65 2c |ary key |of time,|
|00001b80| 20 61 6e 64 20 61 20 73 | 65 63 6f 6e 64 61 72 79 | and a s|econdary|
|00001b90| 0a 6b 65 79 20 6f 66 20 | 63 75 6d 75 6c 61 74 69 |.key of |cumulati|
|00001ba0| 76 65 20 74 69 6d 65 2c | 20 61 6e 64 20 74 68 65 |ve time,| and the|
|00001bb0| 6e 20 70 72 69 6e 74 73 | 20 6f 75 74 20 73 6f 6d |n prints| out som|
|00001bc0| 65 20 6f 66 20 74 68 65 | 20 73 74 61 74 69 73 74 |e of the| statist|
|00001bd0| 69 63 73 2e 0a 54 6f 20 | 62 65 20 73 70 65 63 69 |ics..To |be speci|
|00001be0| 66 69 63 2c 20 74 68 65 | 20 6c 69 73 74 20 69 73 |fic, the| list is|
|00001bf0| 20 66 69 72 73 74 20 63 | 75 6c 6c 65 64 20 64 6f | first c|ulled do|
|00001c00| 77 6e 20 74 6f 20 35 30 | 5c 25 20 28 72 65 3a 20 |wn to 50|\% (re: |
|00001c10| 5c 73 61 6d 70 7b 2e 35 | 7d 29 0a 6f 66 20 69 74 |\samp{.5|}).of it|
|00001c20| 73 20 6f 72 69 67 69 6e | 61 6c 20 73 69 7a 65 2c |s origin|al size,|
|00001c30| 20 74 68 65 6e 20 6f 6e | 6c 79 20 6c 69 6e 65 73 | then on|ly lines|
|00001c40| 20 63 6f 6e 74 61 69 6e | 69 6e 67 20 5c 63 6f 64 | contain|ing \cod|
|00001c50| 65 7b 69 6e 69 74 7d 20 | 61 72 65 0a 6d 61 69 6e |e{init} |are.main|
|00001c60| 74 61 69 6e 65 64 2c 20 | 61 6e 64 20 74 68 61 74 |tained, |and that|
|00001c70| 20 73 75 62 2d 73 75 62 | 2d 6c 69 73 74 20 69 73 | sub-sub|-list is|
|00001c80| 20 70 72 69 6e 74 65 64 | 2e 0a 0a 49 66 20 79 6f | printed|...If yo|
|00001c90| 75 20 77 6f 6e 64 65 72 | 65 64 20 77 68 61 74 20 |u wonder|ed what |
|00001ca0| 66 75 6e 63 74 69 6f 6e | 73 20 63 61 6c 6c 65 64 |function|s called|
|00001cb0| 20 74 68 65 20 61 62 6f | 76 65 20 66 75 6e 63 74 | the abo|ve funct|
|00001cc0| 69 6f 6e 73 2c 20 79 6f | 75 20 63 6f 75 6c 64 0a |ions, yo|u could.|
|00001cd0| 6e 6f 77 20 28 5c 73 61 | 6d 70 7b 70 7d 20 69 73 |now (\sa|mp{p} is|
|00001ce0| 20 73 74 69 6c 6c 20 73 | 6f 72 74 65 64 20 61 63 | still s|orted ac|
|00001cf0| 63 6f 72 64 69 6e 67 20 | 74 6f 20 74 68 65 20 6c |cording |to the l|
|00001d00| 61 73 74 20 63 72 69 74 | 65 72 69 61 29 20 64 6f |ast crit|eria) do|
|00001d10| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |:..\begi|n{verbat|
|00001d20| 69 6d 7d 0a 20 20 20 20 | 70 2e 70 72 69 6e 74 5f |im}. |p.print_|
|00001d30| 63 61 6c 6c 65 72 73 28 | 2e 35 2c 20 27 69 6e 69 |callers(|.5, 'ini|
|00001d40| 74 27 29 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |t').\end|{verbati|
|00001d50| 6d 7d 0a 0a 61 6e 64 20 | 79 6f 75 20 77 6f 75 6c |m}..and |you woul|
|00001d60| 64 20 67 65 74 20 61 20 | 6c 69 73 74 20 6f 66 20 |d get a |list of |
|00001d70| 63 61 6c 6c 65 72 73 20 | 66 6f 72 20 65 61 63 68 |callers |for each|
|00001d80| 20 6f 66 20 74 68 65 20 | 6c 69 73 74 65 64 20 66 | of the |listed f|
|00001d90| 75 6e 63 74 69 6f 6e 73 | 2e 20 0a 0a 49 66 20 79 |unctions|. ..If y|
|00001da0| 6f 75 20 77 61 6e 74 20 | 6d 6f 72 65 20 66 75 6e |ou want |more fun|
|00001db0| 63 74 69 6f 6e 61 6c 69 | 74 79 2c 20 79 6f 75 27 |ctionali|ty, you'|
|00001dc0| 72 65 20 67 6f 69 6e 67 | 20 74 6f 20 68 61 76 65 |re going| to have|
|00001dd0| 20 74 6f 20 72 65 61 64 | 20 74 68 65 0a 6d 61 6e | to read| the.man|
|00001de0| 75 61 6c 2c 20 6f 72 20 | 67 75 65 73 73 20 77 68 |ual, or |guess wh|
|00001df0| 61 74 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |at the f|ollowing|
|00001e00| 20 66 75 6e 63 74 69 6f | 6e 73 20 64 6f 3a 0a 0a | functio|ns do:..|
|00001e10| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00001e20| 0a 20 20 20 20 70 2e 70 | 72 69 6e 74 5f 63 61 6c |. p.p|rint_cal|
|00001e30| 6c 65 65 73 28 29 0a 20 | 20 20 20 70 2e 61 64 64 |lees(). | p.add|
|00001e40| 28 27 66 6f 6f 70 72 6f | 66 27 29 0a 5c 65 6e 64 |('foopro|f').\end|
|00001e50| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 0a 0a 5c 73 65 |{verbati|m}...\se|
|00001e60| 63 74 69 6f 6e 7b 57 68 | 61 74 20 49 73 20 44 65 |ction{Wh|at Is De|
|00001e70| 74 65 72 6d 69 6e 69 73 | 74 69 63 20 50 72 6f 66 |terminis|tic Prof|
|00001e80| 69 6c 69 6e 67 3f 7d 0a | 5c 6e 6f 64 65 6e 61 6d |iling?}.|\nodenam|
|00001e90| 65 7b 44 65 74 65 72 6d | 69 6e 69 73 74 69 63 20 |e{Determ|inistic |
|00001ea0| 50 72 6f 66 69 6c 69 6e | 67 7d 0a 0a 5c 64 66 6e |Profilin|g}..\dfn|
|00001eb0| 7b 44 65 74 65 72 6d 69 | 6e 69 73 74 69 63 20 70 |{Determi|nistic p|
|00001ec0| 72 6f 66 69 6c 69 6e 67 | 7d 20 69 73 20 6d 65 61 |rofiling|} is mea|
|00001ed0| 6e 74 20 74 6f 20 72 65 | 66 6c 65 63 74 20 74 68 |nt to re|flect th|
|00001ee0| 65 20 66 61 63 74 20 74 | 68 61 74 20 61 6c 6c 0a |e fact t|hat all.|
|00001ef0| 5c 64 66 6e 7b 66 75 6e | 63 74 69 6f 6e 20 63 61 |\dfn{fun|ction ca|
|00001f00| 6c 6c 7d 2c 20 5c 64 66 | 6e 7b 66 75 6e 63 74 69 |ll}, \df|n{functi|
|00001f10| 6f 6e 20 72 65 74 75 72 | 6e 7d 2c 20 61 6e 64 20 |on retur|n}, and |
|00001f20| 5c 64 66 6e 7b 65 78 63 | 65 70 74 69 6f 6e 7d 20 |\dfn{exc|eption} |
|00001f30| 65 76 65 6e 74 73 0a 61 | 72 65 20 6d 6f 6e 69 74 |events.a|re monit|
|00001f40| 6f 72 65 64 2c 20 61 6e | 64 20 70 72 65 63 69 73 |ored, an|d precis|
|00001f50| 65 20 74 69 6d 69 6e 67 | 73 20 61 72 65 20 6d 61 |e timing|s are ma|
|00001f60| 64 65 20 66 6f 72 20 74 | 68 65 20 69 6e 74 65 72 |de for t|he inter|
|00001f70| 76 61 6c 73 20 62 65 74 | 77 65 65 6e 0a 74 68 65 |vals bet|ween.the|
|00001f80| 73 65 20 65 76 65 6e 74 | 73 20 28 64 75 72 69 6e |se event|s (durin|
|00001f90| 67 20 77 68 69 63 68 20 | 74 69 6d 65 20 74 68 65 |g which |time the|
|00001fa0| 20 75 73 65 72 27 73 20 | 63 6f 64 65 20 69 73 20 | user's |code is |
|00001fb0| 65 78 65 63 75 74 69 6e | 67 29 2e 20 20 49 6e 0a |executin|g). In.|
|00001fc0| 63 6f 6e 74 72 61 73 74 | 2c 20 5c 64 66 6e 7b 73 |contrast|, \dfn{s|
|00001fd0| 74 61 74 69 73 74 69 63 | 61 6c 20 70 72 6f 66 69 |tatistic|al profi|
|00001fe0| 6c 69 6e 67 7d 20 28 77 | 68 69 63 68 20 69 73 20 |ling} (w|hich is |
|00001ff0| 6e 6f 74 20 64 6f 6e 65 | 20 62 79 20 74 68 69 73 |not done| by this|
|00002000| 0a 6d 6f 64 75 6c 65 29 | 20 72 61 6e 64 6f 6d 6c |.module)| randoml|
|00002010| 79 20 73 61 6d 70 6c 65 | 73 20 74 68 65 20 65 66 |y sample|s the ef|
|00002020| 66 65 63 74 69 76 65 20 | 69 6e 73 74 72 75 63 74 |fective |instruct|
|00002030| 69 6f 6e 20 70 6f 69 6e | 74 65 72 2c 20 61 6e 64 |ion poin|ter, and|
|00002040| 0a 64 65 64 75 63 65 73 | 20 77 68 65 72 65 20 74 |.deduces| where t|
|00002050| 69 6d 65 20 69 73 20 62 | 65 69 6e 67 20 73 70 65 |ime is b|eing spe|
|00002060| 6e 74 2e 20 20 54 68 65 | 20 6c 61 74 74 65 72 20 |nt. The| latter |
|00002070| 74 65 63 68 6e 69 71 75 | 65 20 74 72 61 64 69 74 |techniqu|e tradit|
|00002080| 69 6f 6e 61 6c 6c 79 0a | 69 6e 76 6f 6c 76 65 73 |ionally.|involves|
|00002090| 20 6c 65 73 73 20 6f 76 | 65 72 68 65 61 64 20 28 | less ov|erhead (|
|000020a0| 61 73 20 74 68 65 20 63 | 6f 64 65 20 64 6f 65 73 |as the c|ode does|
|000020b0| 20 6e 6f 74 20 6e 65 65 | 64 20 74 6f 20 62 65 20 | not nee|d to be |
|000020c0| 69 6e 73 74 72 75 6d 65 | 6e 74 65 64 29 2c 0a 62 |instrume|nted),.b|
|000020d0| 75 74 20 70 72 6f 76 69 | 64 65 73 20 6f 6e 6c 79 |ut provi|des only|
|000020e0| 20 72 65 6c 61 74 69 76 | 65 20 69 6e 64 69 63 61 | relativ|e indica|
|000020f0| 74 69 6f 6e 73 20 6f 66 | 20 77 68 65 72 65 20 74 |tions of| where t|
|00002100| 69 6d 65 20 69 73 20 62 | 65 69 6e 67 20 73 70 65 |ime is b|eing spe|
|00002110| 6e 74 2e 0a 0a 49 6e 20 | 50 79 74 68 6f 6e 2c 20 |nt...In |Python, |
|00002120| 73 69 6e 63 65 20 74 68 | 65 72 65 20 69 73 20 61 |since th|ere is a|
|00002130| 6e 20 69 6e 74 65 72 70 | 72 65 74 65 72 20 61 63 |n interp|reter ac|
|00002140| 74 69 76 65 20 64 75 72 | 69 6e 67 20 65 78 65 63 |tive dur|ing exec|
|00002150| 75 74 69 6f 6e 2c 20 74 | 68 65 0a 70 72 65 73 65 |ution, t|he.prese|
|00002160| 6e 63 65 20 6f 66 20 69 | 6e 73 74 72 75 6d 65 6e |nce of i|nstrumen|
|00002170| 74 65 64 20 63 6f 64 65 | 20 69 73 20 6e 6f 74 20 |ted code| is not |
|00002180| 72 65 71 75 69 72 65 64 | 20 74 6f 20 64 6f 20 64 |required| to do d|
|00002190| 65 74 65 72 6d 69 6e 69 | 73 74 69 63 0a 70 72 6f |etermini|stic.pro|
|000021a0| 66 69 6c 69 6e 67 2e 20 | 20 50 79 74 68 6f 6e 20 |filing. | Python |
|000021b0| 61 75 74 6f 6d 61 74 69 | 63 61 6c 6c 79 20 70 72 |automati|cally pr|
|000021c0| 6f 76 69 64 65 73 20 61 | 20 5c 64 66 6e 7b 68 6f |ovides a| \dfn{ho|
|000021d0| 6f 6b 7d 20 28 6f 70 74 | 69 6f 6e 61 6c 0a 63 61 |ok} (opt|ional.ca|
|000021e0| 6c 6c 62 61 63 6b 29 20 | 66 6f 72 20 65 61 63 68 |llback) |for each|
|000021f0| 20 65 76 65 6e 74 2e 20 | 20 49 6e 20 61 64 64 69 | event. | In addi|
|00002200| 74 69 6f 6e 2c 20 74 68 | 65 20 69 6e 74 65 72 70 |tion, th|e interp|
|00002210| 72 65 74 65 64 20 6e 61 | 74 75 72 65 20 6f 66 0a |reted na|ture of.|
|00002220| 50 79 74 68 6f 6e 20 74 | 65 6e 64 73 20 74 6f 20 |Python t|ends to |
|00002230| 61 64 64 20 73 6f 20 6d | 75 63 68 20 6f 76 65 72 |add so m|uch over|
|00002240| 68 65 61 64 20 74 6f 20 | 65 78 65 63 75 74 69 6f |head to |executio|
|00002250| 6e 2c 20 74 68 61 74 20 | 64 65 74 65 72 6d 69 6e |n, that |determin|
|00002260| 69 73 74 69 63 0a 70 72 | 6f 66 69 6c 69 6e 67 20 |istic.pr|ofiling |
|00002270| 74 65 6e 64 73 20 74 6f | 20 6f 6e 6c 79 20 61 64 |tends to| only ad|
|00002280| 64 20 73 6d 61 6c 6c 20 | 70 72 6f 63 65 73 73 69 |d small |processi|
|00002290| 6e 67 20 6f 76 65 72 68 | 65 61 64 20 69 6e 20 74 |ng overh|ead in t|
|000022a0| 79 70 69 63 61 6c 0a 61 | 70 70 6c 69 63 61 74 69 |ypical.a|pplicati|
|000022b0| 6f 6e 73 2e 20 20 54 68 | 65 20 72 65 73 75 6c 74 |ons. Th|e result|
|000022c0| 20 69 73 20 74 68 61 74 | 20 64 65 74 65 72 6d 69 | is that| determi|
|000022d0| 6e 69 73 74 69 63 20 70 | 72 6f 66 69 6c 69 6e 67 |nistic p|rofiling|
|000022e0| 20 69 73 20 6e 6f 74 20 | 74 68 61 74 0a 65 78 70 | is not |that.exp|
|000022f0| 65 6e 73 69 76 65 2c 20 | 79 65 74 20 70 72 6f 76 |ensive, |yet prov|
|00002300| 69 64 65 73 20 65 78 74 | 65 6e 73 69 76 65 20 72 |ides ext|ensive r|
|00002310| 75 6e 20 74 69 6d 65 20 | 73 74 61 74 69 73 74 69 |un time |statisti|
|00002320| 63 73 20 61 62 6f 75 74 | 20 74 68 65 0a 65 78 65 |cs about| the.exe|
|00002330| 63 75 74 69 6f 6e 20 6f | 66 20 61 20 50 79 74 68 |cution o|f a Pyth|
|00002340| 6f 6e 20 70 72 6f 67 72 | 61 6d 2e 0a 0a 43 61 6c |on progr|am...Cal|
|00002350| 6c 20 63 6f 75 6e 74 20 | 73 74 61 74 69 73 74 69 |l count |statisti|
|00002360| 63 73 20 63 61 6e 20 62 | 65 20 75 73 65 64 20 74 |cs can b|e used t|
|00002370| 6f 20 69 64 65 6e 74 69 | 66 79 20 62 75 67 73 20 |o identi|fy bugs |
|00002380| 69 6e 20 63 6f 64 65 20 | 28 73 75 72 70 72 69 73 |in code |(surpris|
|00002390| 69 6e 67 0a 63 6f 75 6e | 74 73 29 2c 20 61 6e 64 |ing.coun|ts), and|
|000023a0| 20 74 6f 20 69 64 65 6e | 74 69 66 79 20 70 6f 73 | to iden|tify pos|
|000023b0| 73 69 62 6c 65 20 69 6e | 6c 69 6e 65 2d 65 78 70 |sible in|line-exp|
|000023c0| 61 6e 73 69 6f 6e 20 70 | 6f 69 6e 74 73 20 28 68 |ansion p|oints (h|
|000023d0| 69 67 68 20 63 61 6c 6c | 0a 63 6f 75 6e 74 73 29 |igh call|.counts)|
|000023e0| 2e 20 20 49 6e 74 65 72 | 6e 61 6c 20 74 69 6d 65 |. Inter|nal time|
|000023f0| 20 73 74 61 74 69 73 74 | 69 63 73 20 63 61 6e 20 | statist|ics can |
|00002400| 62 65 20 75 73 65 64 20 | 74 6f 20 69 64 65 6e 74 |be used |to ident|
|00002410| 69 66 79 20 60 60 68 6f | 74 0a 6c 6f 6f 70 73 27 |ify ``ho|t.loops'|
|00002420| 27 20 74 68 61 74 20 73 | 68 6f 75 6c 64 20 62 65 |' that s|hould be|
|00002430| 20 63 61 72 65 66 75 6c | 6c 79 20 6f 70 74 69 6d | careful|ly optim|
|00002440| 69 7a 65 64 2e 20 20 43 | 75 6d 75 6c 61 74 69 76 |ized. C|umulativ|
|00002450| 65 20 74 69 6d 65 0a 73 | 74 61 74 69 73 74 69 63 |e time.s|tatistic|
|00002460| 73 20 73 68 6f 75 6c 64 | 20 62 65 20 75 73 65 64 |s should| be used|
|00002470| 20 74 6f 20 69 64 65 6e | 74 69 66 79 20 68 69 67 | to iden|tify hig|
|00002480| 68 20 6c 65 76 65 6c 20 | 65 72 72 6f 72 73 20 69 |h level |errors i|
|00002490| 6e 20 74 68 65 0a 73 65 | 6c 65 63 74 69 6f 6e 20 |n the.se|lection |
|000024a0| 6f 66 20 61 6c 67 6f 72 | 69 74 68 6d 73 2e 20 20 |of algor|ithms. |
|000024b0| 4e 6f 74 65 20 74 68 61 | 74 20 74 68 65 20 75 6e |Note tha|t the un|
|000024c0| 75 73 75 61 6c 20 68 61 | 6e 64 6c 69 6e 67 20 6f |usual ha|ndling o|
|000024d0| 66 20 63 75 6d 75 6c 61 | 74 69 76 65 0a 74 69 6d |f cumula|tive.tim|
|000024e0| 65 73 20 69 6e 20 74 68 | 69 73 20 70 72 6f 66 69 |es in th|is profi|
|000024f0| 6c 65 72 20 61 6c 6c 6f | 77 73 20 73 74 61 74 69 |ler allo|ws stati|
|00002500| 73 74 69 63 73 20 66 6f | 72 20 72 65 63 75 72 73 |stics fo|r recurs|
|00002510| 69 76 65 20 69 6d 70 6c | 65 6d 65 6e 74 61 74 69 |ive impl|ementati|
|00002520| 6f 6e 73 0a 6f 66 20 61 | 6c 67 6f 72 69 74 68 6d |ons.of a|lgorithm|
|00002530| 73 20 74 6f 20 62 65 20 | 64 69 72 65 63 74 6c 79 |s to be |directly|
|00002540| 20 63 6f 6d 70 61 72 65 | 64 20 74 6f 20 69 74 65 | compare|d to ite|
|00002550| 72 61 74 69 76 65 20 69 | 6d 70 6c 65 6d 65 6e 74 |rative i|mplement|
|00002560| 61 74 69 6f 6e 73 2e 0a | 0a 0a 5c 73 65 63 74 69 |ations..|..\secti|
|00002570| 6f 6e 7b 52 65 66 65 72 | 65 6e 63 65 20 4d 61 6e |on{Refer|ence Man|
|00002580| 75 61 6c 7d 0a 0a 5c 72 | 65 6e 65 77 63 6f 6d 6d |ual}..\r|enewcomm|
|00002590| 61 6e 64 7b 5c 69 6e 64 | 65 78 73 75 62 69 74 65 |and{\ind|exsubite|
|000025a0| 6d 7d 7b 28 70 72 6f 66 | 69 6c 65 72 20 66 75 6e |m}{(prof|iler fun|
|000025b0| 63 74 69 6f 6e 29 7d 0a | 0a 54 68 65 20 70 72 69 |ction)}.|.The pri|
|000025c0| 6d 61 72 79 20 65 6e 74 | 72 79 20 70 6f 69 6e 74 |mary ent|ry point|
|000025d0| 20 66 6f 72 20 74 68 65 | 20 70 72 6f 66 69 6c 65 | for the| profile|
|000025e0| 72 20 69 73 20 74 68 65 | 20 67 6c 6f 62 61 6c 20 |r is the| global |
|000025f0| 66 75 6e 63 74 69 6f 6e | 0a 5c 63 6f 64 65 7b 70 |function|.\code{p|
|00002600| 72 6f 66 69 6c 65 2e 72 | 75 6e 28 29 7d 2e 20 20 |rofile.r|un()}. |
|00002610| 49 74 20 69 73 20 74 79 | 70 69 63 61 6c 6c 79 20 |It is ty|pically |
|00002620| 75 73 65 64 20 74 6f 20 | 63 72 65 61 74 65 20 61 |used to |create a|
|00002630| 6e 79 20 70 72 6f 66 69 | 6c 65 0a 69 6e 66 6f 72 |ny profi|le.infor|
|00002640| 6d 61 74 69 6f 6e 2e 20 | 20 54 68 65 20 72 65 70 |mation. | The rep|
|00002650| 6f 72 74 73 20 61 72 65 | 20 66 6f 72 6d 61 74 74 |orts are| formatt|
|00002660| 65 64 20 61 6e 64 20 70 | 72 69 6e 74 65 64 20 75 |ed and p|rinted u|
|00002670| 73 69 6e 67 20 6d 65 74 | 68 6f 64 73 20 6f 66 0a |sing met|hods of.|
|00002680| 74 68 65 20 63 6c 61 73 | 73 20 5c 63 6f 64 65 7b |the clas|s \code{|
|00002690| 70 73 74 61 74 73 2e 53 | 74 61 74 73 7d 2e 20 20 |pstats.S|tats}. |
|000026a0| 54 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 69 73 |The foll|owing is|
|000026b0| 20 61 20 64 65 73 63 72 | 69 70 74 69 6f 6e 20 6f | a descr|iption o|
|000026c0| 66 20 61 6c 6c 0a 6f 66 | 20 74 68 65 73 65 20 73 |f all.of| these s|
|000026d0| 74 61 6e 64 61 72 64 20 | 65 6e 74 72 79 20 70 6f |tandard |entry po|
|000026e0| 69 6e 74 73 20 61 6e 64 | 20 66 75 6e 63 74 69 6f |ints and| functio|
|000026f0| 6e 73 2e 20 20 46 6f 72 | 20 61 20 6d 6f 72 65 20 |ns. For| a more |
|00002700| 69 6e 2d 64 65 70 74 68 | 0a 76 69 65 77 20 6f 66 |in-depth|.view of|
|00002710| 20 73 6f 6d 65 20 6f 66 | 20 74 68 65 20 63 6f 64 | some of| the cod|
|00002720| 65 2c 20 63 6f 6e 73 69 | 64 65 72 20 72 65 61 64 |e, consi|der read|
|00002730| 69 6e 67 20 74 68 65 20 | 6c 61 74 65 72 20 73 65 |ing the |later se|
|00002740| 63 74 69 6f 6e 20 6f 6e | 0a 50 72 6f 66 69 6c 65 |ction on|.Profile|
|00002750| 72 20 45 78 74 65 6e 73 | 69 6f 6e 73 2c 20 77 68 |r Extens|ions, wh|
|00002760| 69 63 68 20 69 6e 63 6c | 75 64 65 73 20 64 69 73 |ich incl|udes dis|
|00002770| 63 75 73 73 69 6f 6e 20 | 6f 66 20 68 6f 77 20 74 |cussion |of how t|
|00002780| 6f 20 64 65 72 69 76 65 | 0a 60 60 62 65 74 74 65 |o derive|.``bette|
|00002790| 72 27 27 20 70 72 6f 66 | 69 6c 65 72 73 20 66 72 |r'' prof|ilers fr|
|000027a0| 6f 6d 20 74 68 65 20 63 | 6c 61 73 73 65 73 20 70 |om the c|lasses p|
|000027b0| 72 65 73 65 6e 74 65 64 | 2c 20 6f 72 20 72 65 61 |resented|, or rea|
|000027c0| 64 69 6e 67 20 74 68 65 | 20 73 6f 75 72 63 65 0a |ding the| source.|
|000027d0| 63 6f 64 65 20 66 6f 72 | 20 74 68 65 73 65 20 6d |code for| these m|
|000027e0| 6f 64 75 6c 65 73 2e 0a | 0a 5c 62 65 67 69 6e 7b |odules..|.\begin{|
|000027f0| 66 75 6e 63 64 65 73 63 | 7d 7b 70 72 6f 66 69 6c |funcdesc|}{profil|
|00002800| 65 2e 72 75 6e 7d 7b 73 | 74 72 69 6e 67 5c 6f 70 |e.run}{s|tring\op|
|00002810| 74 69 6f 6e 61 6c 7b 5c | 2c 20 66 69 6c 65 6e 61 |tional{\|, filena|
|00002820| 6d 65 5c 6f 70 74 69 6f | 6e 61 6c 7b 5c 2c 20 2e |me\optio|nal{\, .|
|00002830| 2e 2e 7d 7d 7d 0a 0a 54 | 68 69 73 20 66 75 6e 63 |..}}}..T|his func|
|00002840| 74 69 6f 6e 20 74 61 6b | 65 73 20 61 20 73 69 6e |tion tak|es a sin|
|00002850| 67 6c 65 20 61 72 67 75 | 6d 65 6e 74 20 74 68 61 |gle argu|ment tha|
|00002860| 74 20 68 61 73 20 63 61 | 6e 20 62 65 20 70 61 73 |t has ca|n be pas|
|00002870| 73 65 64 20 74 6f 20 74 | 68 65 0a 5c 63 6f 64 65 |sed to t|he.\code|
|00002880| 7b 65 78 65 63 7d 20 73 | 74 61 74 65 6d 65 6e 74 |{exec} s|tatement|
|00002890| 2c 20 61 6e 64 20 61 6e | 20 6f 70 74 69 6f 6e 61 |, and an| optiona|
|000028a0| 6c 20 66 69 6c 65 20 6e | 61 6d 65 2e 20 20 49 6e |l file n|ame. In|
|000028b0| 20 61 6c 6c 20 63 61 73 | 65 73 20 74 68 69 73 0a | all cas|es this.|
|000028c0| 72 6f 75 74 69 6e 65 20 | 61 74 74 65 6d 70 74 73 |routine |attempts|
|000028d0| 20 74 6f 20 5c 63 6f 64 | 65 7b 65 78 65 63 7d 20 | to \cod|e{exec} |
|000028e0| 69 74 73 20 66 69 72 73 | 74 20 61 72 67 75 6d 65 |its firs|t argume|
|000028f0| 6e 74 2c 20 61 6e 64 20 | 67 61 74 68 65 72 20 70 |nt, and |gather p|
|00002900| 72 6f 66 69 6c 69 6e 67 | 0a 73 74 61 74 69 73 74 |rofiling|.statist|
|00002910| 69 63 73 20 66 72 6f 6d | 20 74 68 65 20 65 78 65 |ics from| the exe|
|00002920| 63 75 74 69 6f 6e 2e 20 | 49 66 20 6e 6f 20 66 69 |cution. |If no fi|
|00002930| 6c 65 20 6e 61 6d 65 20 | 69 73 20 70 72 65 73 65 |le name |is prese|
|00002940| 6e 74 2c 20 74 68 65 6e | 20 74 68 69 73 0a 66 75 |nt, then| this.fu|
|00002950| 6e 63 74 69 6f 6e 20 61 | 75 74 6f 6d 61 74 69 63 |nction a|utomatic|
|00002960| 61 6c 6c 79 20 70 72 69 | 6e 74 73 20 61 20 73 69 |ally pri|nts a si|
|00002970| 6d 70 6c 65 20 70 72 6f | 66 69 6c 69 6e 67 20 72 |mple pro|filing r|
|00002980| 65 70 6f 72 74 2c 20 73 | 6f 72 74 65 64 20 62 79 |eport, s|orted by|
|00002990| 20 74 68 65 0a 73 74 61 | 6e 64 61 72 64 20 6e 61 | the.sta|ndard na|
|000029a0| 6d 65 20 73 74 72 69 6e | 67 20 28 66 69 6c 65 2f |me strin|g (file/|
|000029b0| 6c 69 6e 65 2f 66 75 6e | 63 74 69 6f 6e 2d 6e 61 |line/fun|ction-na|
|000029c0| 6d 65 29 20 74 68 61 74 | 20 69 73 20 70 72 65 73 |me) that| is pres|
|000029d0| 65 6e 74 65 64 20 69 6e | 0a 65 61 63 68 20 6c 69 |ented in|.each li|
|000029e0| 6e 65 2e 20 20 54 68 65 | 20 66 6f 6c 6c 6f 77 69 |ne. The| followi|
|000029f0| 6e 67 20 69 73 20 61 20 | 74 79 70 69 63 61 6c 20 |ng is a |typical |
|00002a00| 6f 75 74 70 75 74 20 66 | 72 6f 6d 20 73 75 63 68 |output f|rom such|
|00002a10| 20 61 20 63 61 6c 6c 3a | 0a 0a 5c 73 6d 61 6c 6c | a call:|..\small|
|00002a20| 7b 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |{.\begin|{verbati|
|00002a30| 6d 7d 0a 20 20 20 20 20 | 20 6d 61 69 6e 28 29 0a |m}. | main().|
|00002a40| 20 20 20 20 20 20 32 37 | 30 36 20 66 75 6e 63 74 | 27|06 funct|
|00002a50| 69 6f 6e 20 63 61 6c 6c | 73 20 28 32 30 30 34 20 |ion call|s (2004 |
|00002a60| 70 72 69 6d 69 74 69 76 | 65 20 63 61 6c 6c 73 29 |primitiv|e calls)|
|00002a70| 20 69 6e 20 34 2e 35 30 | 34 20 43 50 55 20 73 65 | in 4.50|4 CPU se|
|00002a80| 63 6f 6e 64 73 0a 0a 4f | 72 64 65 72 65 64 20 62 |conds..O|rdered b|
|00002a90| 79 3a 20 73 74 61 6e 64 | 61 72 64 20 6e 61 6d 65 |y: stand|ard name|
|00002aa0| 0a 0a 6e 63 61 6c 6c 73 | 20 20 74 6f 74 74 69 6d |..ncalls| tottim|
|00002ab0| 65 20 20 70 65 72 63 61 | 6c 6c 20 20 63 75 6d 74 |e perca|ll cumt|
|00002ac0| 69 6d 65 20 20 70 65 72 | 63 61 6c 6c 20 66 69 6c |ime per|call fil|
|00002ad0| 65 6e 61 6d 65 3a 6c 69 | 6e 65 6e 6f 28 66 75 6e |ename:li|neno(fun|
|00002ae0| 63 74 69 6f 6e 29 0a 20 | 20 20 20 20 32 20 20 20 |ction). | 2 |
|00002af0| 20 30 2e 30 30 36 20 20 | 20 20 30 2e 30 30 33 20 | 0.006 | 0.003 |
|00002b00| 20 20 20 30 2e 39 35 33 | 20 20 20 20 30 2e 34 37 | 0.953| 0.47|
|00002b10| 37 20 70 6f 62 6a 65 63 | 74 2e 70 79 3a 37 35 28 |7 pobjec|t.py:75(|
|00002b20| 73 61 76 65 5f 6f 62 6a | 65 63 74 73 29 0a 20 20 |save_obj|ects). |
|00002b30| 34 33 2f 33 20 20 20 20 | 30 2e 35 33 33 20 20 20 |43/3 |0.533 |
|00002b40| 20 30 2e 30 31 32 20 20 | 20 20 30 2e 37 34 39 20 | 0.012 | 0.749 |
|00002b50| 20 20 20 30 2e 32 35 30 | 20 70 6f 62 6a 65 63 74 | 0.250| pobject|
|00002b60| 2e 70 79 3a 39 39 28 65 | 76 61 6c 75 61 74 65 29 |.py:99(e|valuate)|
|00002b70| 0a 20 2e 2e 2e 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |. ....\e|nd{verba|
|00002b80| 74 69 6d 7d 0a 7d 0a 0a | 54 68 65 20 66 69 72 73 |tim}.}..|The firs|
|00002b90| 74 20 6c 69 6e 65 20 69 | 6e 64 69 63 61 74 65 73 |t line i|ndicates|
|00002ba0| 20 74 68 61 74 20 74 68 | 69 73 20 70 72 6f 66 69 | that th|is profi|
|00002bb0| 6c 65 20 77 61 73 20 67 | 65 6e 65 72 61 74 65 64 |le was g|enerated|
|00002bc0| 20 62 79 20 74 68 65 20 | 63 61 6c 6c 3a 5c 5c 0a | by the |call:\\.|
|00002bd0| 5c 63 6f 64 65 7b 70 72 | 6f 66 69 6c 65 2e 72 75 |\code{pr|ofile.ru|
|00002be0| 6e 28 27 6d 61 69 6e 28 | 29 27 29 7d 2c 20 61 6e |n('main(|)')}, an|
|00002bf0| 64 20 68 65 6e 63 65 20 | 74 68 65 20 65 78 65 63 |d hence |the exec|
|00002c00| 27 65 64 20 73 74 72 69 | 6e 67 20 69 73 0a 5c 63 |'ed stri|ng is.\c|
|00002c10| 6f 64 65 7b 27 6d 61 69 | 6e 28 29 27 7d 2e 20 20 |ode{'mai|n()'}. |
|00002c20| 54 68 65 20 73 65 63 6f | 6e 64 20 6c 69 6e 65 20 |The seco|nd line |
|00002c30| 69 6e 64 69 63 61 74 65 | 73 20 74 68 61 74 20 32 |indicate|s that 2|
|00002c40| 37 30 36 20 63 61 6c 6c | 73 20 77 65 72 65 0a 6d |706 call|s were.m|
|00002c50| 6f 6e 69 74 6f 72 65 64 | 2e 20 20 4f 66 20 74 68 |onitored|. Of th|
|00002c60| 6f 73 65 20 63 61 6c 6c | 73 2c 20 32 30 30 34 20 |ose call|s, 2004 |
|00002c70| 77 65 72 65 20 5c 64 66 | 6e 7b 70 72 69 6d 69 74 |were \df|n{primit|
|00002c80| 69 76 65 7d 2e 20 20 57 | 65 20 64 65 66 69 6e 65 |ive}. W|e define|
|00002c90| 0a 5c 64 66 6e 7b 70 72 | 69 6d 69 74 69 76 65 7d |.\dfn{pr|imitive}|
|00002ca0| 20 74 6f 20 6d 65 61 6e | 20 74 68 61 74 20 74 68 | to mean| that th|
|00002cb0| 65 20 63 61 6c 6c 20 77 | 61 73 20 6e 6f 74 20 69 |e call w|as not i|
|00002cc0| 6e 64 75 63 65 64 20 76 | 69 61 20 72 65 63 75 72 |nduced v|ia recur|
|00002cd0| 73 69 6f 6e 2e 0a 54 68 | 65 20 6e 65 78 74 20 6c |sion..Th|e next l|
|00002ce0| 69 6e 65 3a 20 5c 63 6f | 64 65 7b 4f 72 64 65 72 |ine: \co|de{Order|
|00002cf0| 65 64 20 62 79 3a 5c 20 | 73 74 61 6e 64 61 72 64 |ed by:\ |standard|
|00002d00| 20 6e 61 6d 65 7d 2c 20 | 69 6e 64 69 63 61 74 65 | name}, |indicate|
|00002d10| 73 20 74 68 61 74 0a 74 | 68 65 20 74 65 78 74 20 |s that.t|he text |
|00002d20| 73 74 72 69 6e 67 20 69 | 6e 20 74 68 65 20 66 61 |string i|n the fa|
|00002d30| 72 20 72 69 67 68 74 20 | 63 6f 6c 75 6d 6e 20 77 |r right |column w|
|00002d40| 61 73 20 75 73 65 64 20 | 74 6f 20 73 6f 72 74 20 |as used |to sort |
|00002d50| 74 68 65 20 6f 75 74 70 | 75 74 2e 0a 54 68 65 20 |the outp|ut..The |
|00002d60| 63 6f 6c 75 6d 6e 20 68 | 65 61 64 69 6e 67 73 20 |column h|eadings |
|00002d70| 69 6e 63 6c 75 64 65 3a | 0a 0a 5c 62 65 67 69 6e |include:|..\begin|
|00002d80| 7b 64 65 73 63 72 69 70 | 74 69 6f 6e 7d 0a 0a 5c |{descrip|tion}..\|
|00002d90| 69 74 65 6d 5b 6e 63 61 | 6c 6c 73 20 5d 0a 66 6f |item[nca|lls ].fo|
|00002da0| 72 20 74 68 65 20 6e 75 | 6d 62 65 72 20 6f 66 20 |r the nu|mber of |
|00002db0| 63 61 6c 6c 73 2c 20 0a | 0a 5c 69 74 65 6d 5b 74 |calls, .|.\item[t|
|00002dc0| 6f 74 74 69 6d 65 20 5d | 0a 66 6f 72 20 74 68 65 |ottime ]|.for the|
|00002dd0| 20 74 6f 74 61 6c 20 74 | 69 6d 65 20 73 70 65 6e | total t|ime spen|
|00002de0| 74 20 69 6e 20 74 68 65 | 20 67 69 76 65 6e 20 66 |t in the| given f|
|00002df0| 75 6e 63 74 69 6f 6e 20 | 28 61 6e 64 20 65 78 63 |unction |(and exc|
|00002e00| 6c 75 64 69 6e 67 20 74 | 69 6d 65 0a 6d 61 64 65 |luding t|ime.made|
|00002e10| 20 69 6e 20 63 61 6c 6c | 73 20 74 6f 20 73 75 62 | in call|s to sub|
|00002e20| 2d 66 75 6e 63 74 69 6f | 6e 73 29 2c 0a 0a 5c 69 |-functio|ns),..\i|
|00002e30| 74 65 6d 5b 70 65 72 63 | 61 6c 6c 20 5d 0a 69 73 |tem[perc|all ].is|
|00002e40| 20 74 68 65 20 71 75 6f | 74 69 65 6e 74 20 6f 66 | the quo|tient of|
|00002e50| 20 5c 63 6f 64 65 7b 74 | 6f 74 74 69 6d 65 7d 20 | \code{t|ottime} |
|00002e60| 64 69 76 69 64 65 64 20 | 62 79 20 5c 63 6f 64 65 |divided |by \code|
|00002e70| 7b 6e 63 61 6c 6c 73 7d | 0a 0a 5c 69 74 65 6d 5b |{ncalls}|..\item[|
|00002e80| 63 75 6d 74 69 6d 65 20 | 5d 0a 69 73 20 74 68 65 |cumtime |].is the|
|00002e90| 20 74 6f 74 61 6c 20 74 | 69 6d 65 20 73 70 65 6e | total t|ime spen|
|00002ea0| 74 20 69 6e 20 74 68 69 | 73 20 61 6e 64 20 61 6c |t in thi|s and al|
|00002eb0| 6c 20 73 75 62 66 75 6e | 63 74 69 6f 6e 73 20 28 |l subfun|ctions (|
|00002ec0| 69 2e 65 2e 2c 20 66 72 | 6f 6d 0a 69 6e 76 6f 63 |i.e., fr|om.invoc|
|00002ed0| 61 74 69 6f 6e 20 74 69 | 6c 6c 20 65 78 69 74 29 |ation ti|ll exit)|
|00002ee0| 2e 20 54 68 69 73 20 66 | 69 67 75 72 65 20 69 73 |. This f|igure is|
|00002ef0| 20 61 63 63 75 72 61 74 | 65 20 5c 65 6d 70 68 7b | accurat|e \emph{|
|00002f00| 65 76 65 6e 7d 20 66 6f | 72 20 72 65 63 75 72 73 |even} fo|r recurs|
|00002f10| 69 76 65 0a 66 75 6e 63 | 74 69 6f 6e 73 2e 0a 0a |ive.func|tions...|
|00002f20| 5c 69 74 65 6d 5b 70 65 | 72 63 61 6c 6c 20 5d 0a |\item[pe|rcall ].|
|00002f30| 69 73 20 74 68 65 20 71 | 75 6f 74 69 65 6e 74 20 |is the q|uotient |
|00002f40| 6f 66 20 5c 63 6f 64 65 | 7b 63 75 6d 74 69 6d 65 |of \code|{cumtime|
|00002f50| 7d 20 64 69 76 69 64 65 | 64 20 62 79 20 70 72 69 |} divide|d by pri|
|00002f60| 6d 69 74 69 76 65 20 63 | 61 6c 6c 73 0a 0a 5c 69 |mitive c|alls..\i|
|00002f70| 74 65 6d 5b 66 69 6c 65 | 6e 61 6d 65 3a 6c 69 6e |tem[file|name:lin|
|00002f80| 65 6e 6f 28 66 75 6e 63 | 74 69 6f 6e 29 20 5d 0a |eno(func|tion) ].|
|00002f90| 70 72 6f 76 69 64 65 73 | 20 74 68 65 20 72 65 73 |provides| the res|
|00002fa0| 70 65 63 74 69 76 65 20 | 64 61 74 61 20 6f 66 20 |pective |data of |
|00002fb0| 65 61 63 68 20 66 75 6e | 63 74 69 6f 6e 0a 0a 5c |each fun|ction..\|
|00002fc0| 65 6e 64 7b 64 65 73 63 | 72 69 70 74 69 6f 6e 7d |end{desc|ription}|
|00002fd0| 0a 0a 57 68 65 6e 20 74 | 68 65 72 65 20 61 72 65 |..When t|here are|
|00002fe0| 20 74 77 6f 20 6e 75 6d | 62 65 72 73 20 69 6e 20 | two num|bers in |
|00002ff0| 74 68 65 20 66 69 72 73 | 74 20 63 6f 6c 75 6d 6e |the firs|t column|
|00003000| 20 28 65 2e 67 2e 3a 20 | 5c 73 61 6d 70 7b 34 33 | (e.g.: |\samp{43|
|00003010| 2f 33 7d 29 2c 0a 74 68 | 65 6e 20 74 68 65 20 6c |/3}),.th|en the l|
|00003020| 61 74 74 65 72 20 69 73 | 20 74 68 65 20 6e 75 6d |atter is| the num|
|00003030| 62 65 72 20 6f 66 20 70 | 72 69 6d 69 74 69 76 65 |ber of p|rimitive|
|00003040| 20 63 61 6c 6c 73 2c 20 | 61 6e 64 20 74 68 65 20 | calls, |and the |
|00003050| 66 6f 72 6d 65 72 20 69 | 73 0a 74 68 65 20 61 63 |former i|s.the ac|
|00003060| 74 75 61 6c 20 6e 75 6d | 62 65 72 20 6f 66 20 63 |tual num|ber of c|
|00003070| 61 6c 6c 73 2e 20 20 4e | 6f 74 65 20 74 68 61 74 |alls. N|ote that|
|00003080| 20 77 68 65 6e 20 74 68 | 65 20 66 75 6e 63 74 69 | when th|e functi|
|00003090| 6f 6e 20 64 6f 65 73 20 | 6e 6f 74 0a 72 65 63 75 |on does |not.recu|
|000030a0| 72 73 65 2c 20 74 68 65 | 73 65 20 74 77 6f 20 76 |rse, the|se two v|
|000030b0| 61 6c 75 65 73 20 61 72 | 65 20 74 68 65 20 73 61 |alues ar|e the sa|
|000030c0| 6d 65 2c 20 61 6e 64 20 | 6f 6e 6c 79 20 74 68 65 |me, and |only the|
|000030d0| 20 73 69 6e 67 6c 65 20 | 66 69 67 75 72 65 20 69 | single |figure i|
|000030e0| 73 0a 70 72 69 6e 74 65 | 64 2e 0a 0a 5c 65 6e 64 |s.printe|d...\end|
|000030f0| 7b 66 75 6e 63 64 65 73 | 63 7d 0a 0a 5c 62 65 67 |{funcdes|c}..\beg|
|00003100| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 70 73 74 |in{funcd|esc}{pst|
|00003110| 61 74 73 2e 53 74 61 74 | 73 7d 7b 66 69 6c 65 6e |ats.Stat|s}{filen|
|00003120| 61 6d 65 5c 6f 70 74 69 | 6f 6e 61 6c 7b 5c 2c 20 |ame\opti|onal{\, |
|00003130| 2e 2e 2e 7d 7d 0a 54 68 | 69 73 20 63 6c 61 73 73 |...}}.Th|is class|
|00003140| 20 63 6f 6e 73 74 72 75 | 63 74 6f 72 20 63 72 65 | constru|ctor cre|
|00003150| 61 74 65 73 20 61 6e 20 | 69 6e 73 74 61 6e 63 65 |ates an |instance|
|00003160| 20 6f 66 20 61 20 60 60 | 73 74 61 74 69 73 74 69 | of a ``|statisti|
|00003170| 63 73 20 6f 62 6a 65 63 | 74 27 27 0a 66 72 6f 6d |cs objec|t''.from|
|00003180| 20 61 20 5c 76 61 72 7b | 66 69 6c 65 6e 61 6d 65 | a \var{|filename|
|00003190| 7d 20 28 6f 72 20 73 65 | 74 20 6f 66 20 66 69 6c |} (or se|t of fil|
|000031a0| 65 6e 61 6d 65 73 29 2e | 20 20 5c 63 6f 64 65 7b |enames).| \code{|
|000031b0| 53 74 61 74 73 7d 20 6f | 62 6a 65 63 74 73 20 61 |Stats} o|bjects a|
|000031c0| 72 65 0a 6d 61 6e 69 70 | 75 6c 61 74 65 64 20 62 |re.manip|ulated b|
|000031d0| 79 20 6d 65 74 68 6f 64 | 73 2c 20 69 6e 20 6f 72 |y method|s, in or|
|000031e0| 64 65 72 20 74 6f 20 70 | 72 69 6e 74 20 75 73 65 |der to p|rint use|
|000031f0| 66 75 6c 20 72 65 70 6f | 72 74 73 2e 0a 0a 54 68 |ful repo|rts...Th|
|00003200| 65 20 66 69 6c 65 20 73 | 65 6c 65 63 74 65 64 20 |e file s|elected |
|00003210| 62 79 20 74 68 65 20 61 | 62 6f 76 65 20 63 6f 6e |by the a|bove con|
|00003220| 73 74 72 75 63 74 6f 72 | 20 6d 75 73 74 20 68 61 |structor| must ha|
|00003230| 76 65 20 62 65 65 6e 20 | 63 72 65 61 74 65 64 20 |ve been |created |
|00003240| 62 79 0a 74 68 65 20 63 | 6f 72 72 65 73 70 6f 6e |by.the c|orrespon|
|00003250| 64 69 6e 67 20 76 65 72 | 73 69 6f 6e 20 6f 66 20 |ding ver|sion of |
|00003260| 5c 63 6f 64 65 7b 70 72 | 6f 66 69 6c 65 7d 2e 20 |\code{pr|ofile}. |
|00003270| 20 54 6f 20 62 65 20 73 | 70 65 63 69 66 69 63 2c | To be s|pecific,|
|00003280| 20 74 68 65 72 65 20 69 | 73 0a 5c 65 6d 70 68 7b | there i|s.\emph{|
|00003290| 4e 4f 7d 20 66 69 6c 65 | 20 63 6f 6d 70 61 74 69 |NO} file| compati|
|000032a0| 62 69 6c 69 74 79 20 67 | 75 61 72 61 6e 74 65 65 |bility g|uarantee|
|000032b0| 64 20 77 69 74 68 20 66 | 75 74 75 72 65 20 76 65 |d with f|uture ve|
|000032c0| 72 73 69 6f 6e 73 20 6f | 66 20 74 68 69 73 0a 70 |rsions o|f this.p|
|000032d0| 72 6f 66 69 6c 65 72 2c | 20 61 6e 64 20 74 68 65 |rofiler,| and the|
|000032e0| 72 65 20 69 73 20 6e 6f | 20 63 6f 6d 70 61 74 69 |re is no| compati|
|000032f0| 62 69 6c 69 74 79 20 77 | 69 74 68 20 66 69 6c 65 |bility w|ith file|
|00003300| 73 20 70 72 6f 64 75 63 | 65 64 20 62 79 20 6f 74 |s produc|ed by ot|
|00003310| 68 65 72 0a 70 72 6f 66 | 69 6c 65 72 73 20 28 65 |her.prof|ilers (e|
|00003320| 2e 67 2e 2c 20 74 68 65 | 20 6f 6c 64 20 73 79 73 |.g., the| old sys|
|00003330| 74 65 6d 20 70 72 6f 66 | 69 6c 65 72 29 2e 0a 0a |tem prof|iler)...|
|00003340| 49 66 20 73 65 76 65 72 | 61 6c 20 66 69 6c 65 73 |If sever|al files|
|00003350| 20 61 72 65 20 70 72 6f | 76 69 64 65 64 2c 20 61 | are pro|vided, a|
|00003360| 6c 6c 20 74 68 65 20 73 | 74 61 74 69 73 74 69 63 |ll the s|tatistic|
|00003370| 73 20 66 6f 72 20 69 64 | 65 6e 74 69 63 61 6c 0a |s for id|entical.|
|00003380| 66 75 6e 63 74 69 6f 6e | 73 20 77 69 6c 6c 20 62 |function|s will b|
|00003390| 65 20 63 6f 61 6c 65 73 | 63 65 64 2c 20 73 6f 20 |e coales|ced, so |
|000033a0| 74 68 61 74 20 61 6e 20 | 6f 76 65 72 61 6c 6c 20 |that an |overall |
|000033b0| 76 69 65 77 20 6f 66 20 | 73 65 76 65 72 61 6c 0a |view of |several.|
|000033c0| 70 72 6f 63 65 73 73 65 | 73 20 63 61 6e 20 62 65 |processe|s can be|
|000033d0| 20 63 6f 6e 73 69 64 65 | 72 65 64 20 69 6e 20 61 | conside|red in a|
|000033e0| 20 73 69 6e 67 6c 65 20 | 72 65 70 6f 72 74 2e 20 | single |report. |
|000033f0| 20 49 66 20 61 64 64 69 | 74 69 6f 6e 61 6c 20 66 | If addi|tional f|
|00003400| 69 6c 65 73 0a 6e 65 65 | 64 20 74 6f 20 62 65 20 |iles.nee|d to be |
|00003410| 63 6f 6d 62 69 6e 65 64 | 20 77 69 74 68 20 64 61 |combined| with da|
|00003420| 74 61 20 69 6e 20 61 6e | 20 65 78 69 73 74 69 6e |ta in an| existin|
|00003430| 67 20 5c 63 6f 64 65 7b | 53 74 61 74 73 7d 20 6f |g \code{|Stats} o|
|00003440| 62 6a 65 63 74 2c 20 74 | 68 65 0a 5c 63 6f 64 65 |bject, t|he.\code|
|00003450| 7b 61 64 64 28 29 7d 20 | 6d 65 74 68 6f 64 20 63 |{add()} |method c|
|00003460| 61 6e 20 62 65 20 75 73 | 65 64 2e 0a 5c 65 6e 64 |an be us|ed..\end|
|00003470| 7b 66 75 6e 63 64 65 73 | 63 7d 0a 0a 0a 5c 73 75 |{funcdes|c}...\su|
|00003480| 62 73 65 63 74 69 6f 6e | 7b 54 68 65 20 5c 73 65 |bsection|{The \se|
|00003490| 63 74 63 6f 64 65 7b 53 | 74 61 74 73 7d 20 43 6c |ctcode{S|tats} Cl|
|000034a0| 61 73 73 7d 0a 0a 5c 72 | 65 6e 65 77 63 6f 6d 6d |ass}..\r|enewcomm|
|000034b0| 61 6e 64 7b 5c 69 6e 64 | 65 78 73 75 62 69 74 65 |and{\ind|exsubite|
|000034c0| 6d 7d 7b 28 53 74 61 74 | 73 20 6d 65 74 68 6f 64 |m}{(Stat|s method|
|000034d0| 29 7d 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |)}..\beg|in{funcd|
|000034e0| 65 73 63 7d 7b 73 74 72 | 69 70 5f 64 69 72 73 7d |esc}{str|ip_dirs}|
|000034f0| 7b 7d 0a 54 68 69 73 20 | 6d 65 74 68 6f 64 20 66 |{}.This |method f|
|00003500| 6f 72 20 74 68 65 20 5c | 63 6f 64 65 7b 53 74 61 |or the \|code{Sta|
|00003510| 74 73 7d 20 63 6c 61 73 | 73 20 72 65 6d 6f 76 65 |ts} clas|s remove|
|00003520| 73 20 61 6c 6c 20 6c 65 | 61 64 69 6e 67 20 70 61 |s all le|ading pa|
|00003530| 74 68 20 69 6e 66 6f 72 | 6d 61 74 69 6f 6e 0a 66 |th infor|mation.f|
|00003540| 72 6f 6d 20 66 69 6c 65 | 20 6e 61 6d 65 73 2e 20 |rom file| names. |
|00003550| 20 49 74 20 69 73 20 76 | 65 72 79 20 75 73 65 66 | It is v|ery usef|
|00003560| 75 6c 20 69 6e 20 72 65 | 64 75 63 69 6e 67 20 74 |ul in re|ducing t|
|00003570| 68 65 20 73 69 7a 65 20 | 6f 66 20 74 68 65 0a 70 |he size |of the.p|
|00003580| 72 69 6e 74 6f 75 74 20 | 74 6f 20 66 69 74 20 77 |rintout |to fit w|
|00003590| 69 74 68 69 6e 20 28 63 | 6c 6f 73 65 20 74 6f 29 |ithin (c|lose to)|
|000035a0| 20 38 30 20 63 6f 6c 75 | 6d 6e 73 2e 20 20 54 68 | 80 colu|mns. Th|
|000035b0| 69 73 20 6d 65 74 68 6f | 64 20 6d 6f 64 69 66 69 |is metho|d modifi|
|000035c0| 65 73 0a 74 68 65 20 6f | 62 6a 65 63 74 2c 20 61 |es.the o|bject, a|
|000035d0| 6e 64 20 74 68 65 20 73 | 74 72 69 70 70 65 64 20 |nd the s|tripped |
|000035e0| 69 6e 66 6f 72 6d 61 74 | 69 6f 6e 20 69 73 20 6c |informat|ion is l|
|000035f0| 6f 73 74 2e 20 20 41 66 | 74 65 72 20 70 65 72 66 |ost. Af|ter perf|
|00003600| 6f 72 6d 69 6e 67 20 61 | 0a 73 74 72 69 70 20 6f |orming a|.strip o|
|00003610| 70 65 72 61 74 69 6f 6e | 2c 20 74 68 65 20 6f 62 |peration|, the ob|
|00003620| 6a 65 63 74 20 69 73 20 | 63 6f 6e 73 69 64 65 72 |ject is |consider|
|00003630| 65 64 20 74 6f 20 68 61 | 76 65 20 69 74 73 20 65 |ed to ha|ve its e|
|00003640| 6e 74 72 69 65 73 20 69 | 6e 20 61 0a 60 60 72 61 |ntries i|n a.``ra|
|00003650| 6e 64 6f 6d 27 27 20 6f | 72 64 65 72 2c 20 61 73 |ndom'' o|rder, as|
|00003660| 20 69 74 20 77 61 73 20 | 6a 75 73 74 20 61 66 74 | it was |just aft|
|00003670| 65 72 20 6f 62 6a 65 63 | 74 20 69 6e 69 74 69 61 |er objec|t initia|
|00003680| 6c 69 7a 61 74 69 6f 6e | 20 61 6e 64 0a 6c 6f 61 |lization| and.loa|
|00003690| 64 69 6e 67 2e 20 20 49 | 66 20 5c 63 6f 64 65 7b |ding. I|f \code{|
|000036a0| 73 74 72 69 70 5f 64 69 | 72 73 28 29 7d 20 63 61 |strip_di|rs()} ca|
|000036b0| 75 73 65 73 20 74 77 6f | 20 66 75 6e 63 74 69 6f |uses two| functio|
|000036c0| 6e 20 6e 61 6d 65 73 20 | 74 6f 20 62 65 0a 69 6e |n names |to be.in|
|000036d0| 64 69 73 74 69 6e 67 75 | 69 73 68 61 62 6c 65 20 |distingu|ishable |
|000036e0| 28 69 2e 65 2e 2c 20 74 | 68 65 79 20 61 72 65 20 |(i.e., t|hey are |
|000036f0| 6f 6e 20 74 68 65 20 73 | 61 6d 65 20 6c 69 6e 65 |on the s|ame line|
|00003700| 20 6f 66 20 74 68 65 20 | 73 61 6d 65 0a 66 69 6c | of the |same.fil|
|00003710| 65 6e 61 6d 65 2c 20 61 | 6e 64 20 68 61 76 65 20 |ename, a|nd have |
|00003720| 74 68 65 20 73 61 6d 65 | 20 66 75 6e 63 74 69 6f |the same| functio|
|00003730| 6e 20 6e 61 6d 65 29 2c | 20 74 68 65 6e 20 74 68 |n name),| then th|
|00003740| 65 20 73 74 61 74 69 73 | 74 69 63 73 20 66 6f 72 |e statis|tics for|
|00003750| 0a 74 68 65 73 65 20 74 | 77 6f 20 65 6e 74 72 69 |.these t|wo entri|
|00003760| 65 73 20 61 72 65 20 61 | 63 63 75 6d 75 6c 61 74 |es are a|ccumulat|
|00003770| 65 64 20 69 6e 74 6f 20 | 61 20 73 69 6e 67 6c 65 |ed into |a single|
|00003780| 20 65 6e 74 72 79 2e 0a | 5c 65 6e 64 7b 66 75 6e | entry..|\end{fun|
|00003790| 63 64 65 73 63 7d 0a 0a | 0a 5c 62 65 67 69 6e 7b |cdesc}..|.\begin{|
|000037a0| 66 75 6e 63 64 65 73 63 | 7d 7b 61 64 64 7d 7b 66 |funcdesc|}{add}{f|
|000037b0| 69 6c 65 6e 61 6d 65 5c | 6f 70 74 69 6f 6e 61 6c |ilename\|optional|
|000037c0| 7b 5c 2c 20 2e 2e 2e 7d | 7d 0a 54 68 69 73 20 6d |{\, ...}|}.This m|
|000037d0| 65 74 68 6f 64 20 6f 66 | 20 74 68 65 20 5c 63 6f |ethod of| the \co|
|000037e0| 64 65 7b 53 74 61 74 73 | 7d 20 63 6c 61 73 73 20 |de{Stats|} class |
|000037f0| 61 63 63 75 6d 75 6c 61 | 74 65 73 20 61 64 64 69 |accumula|tes addi|
|00003800| 74 69 6f 6e 61 6c 20 70 | 72 6f 66 69 6c 69 6e 67 |tional p|rofiling|
|00003810| 0a 69 6e 66 6f 72 6d 61 | 74 69 6f 6e 20 69 6e 74 |.informa|tion int|
|00003820| 6f 20 74 68 65 20 63 75 | 72 72 65 6e 74 20 70 72 |o the cu|rrent pr|
|00003830| 6f 66 69 6c 69 6e 67 20 | 6f 62 6a 65 63 74 2e 20 |ofiling |object. |
|00003840| 20 49 74 73 20 61 72 67 | 75 6d 65 6e 74 73 20 73 | Its arg|uments s|
|00003850| 68 6f 75 6c 64 0a 72 65 | 66 65 72 20 74 6f 20 66 |hould.re|fer to f|
|00003860| 69 6c 65 6e 61 6d 65 73 | 20 63 72 65 61 74 65 64 |ilenames| created|
|00003870| 20 62 79 20 74 68 65 20 | 63 6f 72 72 65 73 70 6f | by the |correspo|
|00003880| 6e 64 69 6e 67 20 76 65 | 72 73 69 6f 6e 20 6f 66 |nding ve|rsion of|
|00003890| 0a 5c 63 6f 64 65 7b 70 | 72 6f 66 69 6c 65 2e 72 |.\code{p|rofile.r|
|000038a0| 75 6e 28 29 7d 2e 20 20 | 53 74 61 74 69 73 74 69 |un()}. |Statisti|
|000038b0| 63 73 20 66 6f 72 20 69 | 64 65 6e 74 69 63 61 6c |cs for i|dentical|
|000038c0| 6c 79 20 6e 61 6d 65 64 | 20 28 72 65 3a 20 66 69 |ly named| (re: fi|
|000038d0| 6c 65 2c 0a 6c 69 6e 65 | 2c 20 6e 61 6d 65 29 20 |le,.line|, name) |
|000038e0| 66 75 6e 63 74 69 6f 6e | 73 20 61 72 65 20 61 75 |function|s are au|
|000038f0| 74 6f 6d 61 74 69 63 61 | 6c 6c 79 20 61 63 63 75 |tomatica|lly accu|
|00003900| 6d 75 6c 61 74 65 64 20 | 69 6e 74 6f 20 73 69 6e |mulated |into sin|
|00003910| 67 6c 65 0a 66 75 6e 63 | 74 69 6f 6e 20 73 74 61 |gle.func|tion sta|
|00003920| 74 69 73 74 69 63 73 2e | 0a 5c 65 6e 64 7b 66 75 |tistics.|.\end{fu|
|00003930| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00003940| 66 75 6e 63 64 65 73 63 | 7d 7b 73 6f 72 74 5f 73 |funcdesc|}{sort_s|
|00003950| 74 61 74 73 7d 7b 6b 65 | 79 5c 6f 70 74 69 6f 6e |tats}{ke|y\option|
|00003960| 61 6c 7b 5c 2c 20 2e 2e | 2e 7d 7d 0a 54 68 69 73 |al{\, ..|.}}.This|
|00003970| 20 6d 65 74 68 6f 64 20 | 6d 6f 64 69 66 69 65 73 | method |modifies|
|00003980| 20 74 68 65 20 5c 63 6f | 64 65 7b 53 74 61 74 73 | the \co|de{Stats|
|00003990| 7d 20 6f 62 6a 65 63 74 | 20 62 79 20 73 6f 72 74 |} object| by sort|
|000039a0| 69 6e 67 20 69 74 20 61 | 63 63 6f 72 64 69 6e 67 |ing it a|ccording|
|000039b0| 20 74 6f 20 74 68 65 0a | 73 75 70 70 6c 69 65 64 | to the.|supplied|
|000039c0| 20 63 72 69 74 65 72 69 | 61 2e 20 20 54 68 65 20 | criteri|a. The |
|000039d0| 61 72 67 75 6d 65 6e 74 | 20 69 73 20 74 79 70 69 |argument| is typi|
|000039e0| 63 61 6c 6c 79 20 61 20 | 73 74 72 69 6e 67 20 69 |cally a |string i|
|000039f0| 64 65 6e 74 69 66 79 69 | 6e 67 20 74 68 65 0a 62 |dentifyi|ng the.b|
|00003a00| 61 73 69 73 20 6f 66 20 | 61 20 73 6f 72 74 20 28 |asis of |a sort (|
|00003a10| 65 78 61 6d 70 6c 65 3a | 20 5c 63 6f 64 65 7b 22 |example:| \code{"|
|00003a20| 74 69 6d 65 22 7d 20 6f | 72 20 5c 63 6f 64 65 7b |time"} o|r \code{|
|00003a30| 22 6e 61 6d 65 22 7d 29 | 2e 0a 0a 57 68 65 6e 20 |"name"})|...When |
|00003a40| 6d 6f 72 65 20 74 68 61 | 6e 20 6f 6e 65 20 6b 65 |more tha|n one ke|
|00003a50| 79 20 69 73 20 70 72 6f | 76 69 64 65 64 2c 20 74 |y is pro|vided, t|
|00003a60| 68 65 6e 20 61 64 64 69 | 74 69 6f 6e 61 6c 20 6b |hen addi|tional k|
|00003a70| 65 79 73 20 61 72 65 20 | 75 73 65 64 20 61 73 0a |eys are |used as.|
|00003a80| 73 65 63 6f 6e 64 61 72 | 79 20 63 72 69 74 65 72 |secondar|y criter|
|00003a90| 69 61 20 77 68 65 6e 20 | 74 68 65 20 74 68 65 72 |ia when |the ther|
|00003aa0| 65 20 69 73 20 65 71 75 | 61 6c 69 74 79 20 69 6e |e is equ|ality in|
|00003ab0| 20 61 6c 6c 20 6b 65 79 | 73 20 73 65 6c 65 63 74 | all key|s select|
|00003ac0| 65 64 0a 62 65 66 6f 72 | 65 20 74 68 65 6d 2e 20 |ed.befor|e them. |
|00003ad0| 20 46 6f 72 20 65 78 61 | 6d 70 6c 65 2c 20 73 6f | For exa|mple, so|
|00003ae0| 72 74 5f 73 74 61 74 73 | 28 27 6e 61 6d 65 27 2c |rt_stats|('name',|
|00003af0| 20 27 66 69 6c 65 27 29 | 20 77 69 6c 6c 20 73 6f | 'file')| will so|
|00003b00| 72 74 20 61 6c 6c 0a 74 | 68 65 20 65 6e 74 72 69 |rt all.t|he entri|
|00003b10| 65 73 20 61 63 63 6f 72 | 64 69 6e 67 20 74 6f 20 |es accor|ding to |
|00003b20| 74 68 65 69 72 20 66 75 | 6e 63 74 69 6f 6e 20 6e |their fu|nction n|
|00003b30| 61 6d 65 2c 20 61 6e 64 | 20 72 65 73 6f 6c 76 65 |ame, and| resolve|
|00003b40| 20 61 6c 6c 20 74 69 65 | 73 0a 28 69 64 65 6e 74 | all tie|s.(ident|
|00003b50| 69 63 61 6c 20 66 75 6e | 63 74 69 6f 6e 20 6e 61 |ical fun|ction na|
|00003b60| 6d 65 73 29 20 62 79 20 | 73 6f 72 74 69 6e 67 20 |mes) by |sorting |
|00003b70| 62 79 20 66 69 6c 65 20 | 6e 61 6d 65 2e 0a 0a 41 |by file |name...A|
|00003b80| 62 62 72 65 76 69 61 74 | 69 6f 6e 73 20 63 61 6e |bbreviat|ions can|
|00003b90| 20 62 65 20 75 73 65 64 | 20 66 6f 72 20 61 6e 79 | be used| for any|
|00003ba0| 20 6b 65 79 20 6e 61 6d | 65 73 2c 20 61 73 20 6c | key nam|es, as l|
|00003bb0| 6f 6e 67 20 61 73 20 74 | 68 65 0a 61 62 62 72 65 |ong as t|he.abbre|
|00003bc0| 76 69 61 74 69 6f 6e 20 | 69 73 20 75 6e 61 6d 62 |viation |is unamb|
|00003bd0| 69 67 75 6f 75 73 2e 20 | 20 54 68 65 20 66 6f 6c |iguous. | The fol|
|00003be0| 6c 6f 77 69 6e 67 20 61 | 72 65 20 74 68 65 20 6b |lowing a|re the k|
|00003bf0| 65 79 73 20 63 75 72 72 | 65 6e 74 6c 79 0a 64 65 |eys curr|ently.de|
|00003c00| 66 69 6e 65 64 3a 20 0a | 0a 5c 62 65 67 69 6e 7b |fined: .|.\begin{|
|00003c10| 74 61 62 6c 65 69 69 7d | 7b 7c 6c 7c 6c 7c 7d 7b |tableii}|{|l|l|}{|
|00003c20| 63 6f 64 65 7d 7b 56 61 | 6c 69 64 20 41 72 67 7d |code}{Va|lid Arg}|
|00003c30| 7b 4d 65 61 6e 69 6e 67 | 7d 0a 5c 6c 69 6e 65 69 |{Meaning|}.\linei|
|00003c40| 69 7b 22 63 61 6c 6c 73 | 22 7d 7b 63 61 6c 6c 20 |i{"calls|"}{call |
|00003c50| 63 6f 75 6e 74 7d 0a 5c | 6c 69 6e 65 69 69 7b 22 |count}.\|lineii{"|
|00003c60| 63 75 6d 75 6c 61 74 69 | 76 65 22 7d 7b 63 75 6d |cumulati|ve"}{cum|
|00003c70| 75 6c 61 74 69 76 65 20 | 74 69 6d 65 7d 0a 5c 6c |ulative |time}.\l|
|00003c80| 69 6e 65 69 69 7b 22 66 | 69 6c 65 22 7d 7b 66 69 |ineii{"f|ile"}{fi|
|00003c90| 6c 65 20 6e 61 6d 65 7d | 0a 5c 6c 69 6e 65 69 69 |le name}|.\lineii|
|00003ca0| 7b 22 6d 6f 64 75 6c 65 | 22 7d 7b 66 69 6c 65 20 |{"module|"}{file |
|00003cb0| 6e 61 6d 65 7d 0a 5c 6c | 69 6e 65 69 69 7b 22 70 |name}.\l|ineii{"p|
|00003cc0| 63 61 6c 6c 73 22 7d 7b | 70 72 69 6d 69 74 69 76 |calls"}{|primitiv|
|00003cd0| 65 20 63 61 6c 6c 20 63 | 6f 75 6e 74 7d 0a 5c 6c |e call c|ount}.\l|
|00003ce0| 69 6e 65 69 69 7b 22 6c | 69 6e 65 22 7d 7b 6c 69 |ineii{"l|ine"}{li|
|00003cf0| 6e 65 20 6e 75 6d 62 65 | 72 7d 0a 5c 6c 69 6e 65 |ne numbe|r}.\line|
|00003d00| 69 69 7b 22 6e 61 6d 65 | 22 7d 7b 66 75 6e 63 74 |ii{"name|"}{funct|
|00003d10| 69 6f 6e 20 6e 61 6d 65 | 7d 0a 5c 6c 69 6e 65 69 |ion name|}.\linei|
|00003d20| 69 7b 22 6e 66 6c 22 7d | 7b 6e 61 6d 65 2f 66 69 |i{"nfl"}|{name/fi|
|00003d30| 6c 65 2f 6c 69 6e 65 7d | 0a 5c 6c 69 6e 65 69 69 |le/line}|.\lineii|
|00003d40| 7b 22 73 74 64 6e 61 6d | 65 22 7d 7b 73 74 61 6e |{"stdnam|e"}{stan|
|00003d50| 64 61 72 64 20 6e 61 6d | 65 7d 0a 5c 6c 69 6e 65 |dard nam|e}.\line|
|00003d60| 69 69 7b 22 74 69 6d 65 | 22 7d 7b 69 6e 74 65 72 |ii{"time|"}{inter|
|00003d70| 6e 61 6c 20 74 69 6d 65 | 7d 0a 5c 65 6e 64 7b 74 |nal time|}.\end{t|
|00003d80| 61 62 6c 65 69 69 7d 0a | 0a 4e 6f 74 65 20 74 68 |ableii}.|.Note th|
|00003d90| 61 74 20 61 6c 6c 20 73 | 6f 72 74 73 20 6f 6e 20 |at all s|orts on |
|00003da0| 73 74 61 74 69 73 74 69 | 63 73 20 61 72 65 20 69 |statisti|cs are i|
|00003db0| 6e 20 64 65 73 63 65 6e | 64 69 6e 67 20 6f 72 64 |n descen|ding ord|
|00003dc0| 65 72 20 28 70 6c 61 63 | 69 6e 67 0a 6d 6f 73 74 |er (plac|ing.most|
|00003dd0| 20 74 69 6d 65 20 63 6f | 6e 73 75 6d 69 6e 67 20 | time co|nsuming |
|00003de0| 69 74 65 6d 73 20 66 69 | 72 73 74 29 2c 20 77 68 |items fi|rst), wh|
|00003df0| 65 72 65 20 61 73 20 6e | 61 6d 65 2c 20 66 69 6c |ere as n|ame, fil|
|00003e00| 65 2c 20 61 6e 64 20 6c | 69 6e 65 20 6e 75 6d 62 |e, and l|ine numb|
|00003e10| 65 72 0a 73 65 61 72 63 | 68 65 73 20 61 72 65 20 |er.searc|hes are |
|00003e20| 69 6e 20 61 73 63 65 6e | 64 69 6e 67 20 6f 72 64 |in ascen|ding ord|
|00003e30| 65 72 20 28 69 2e 65 2e | 2c 20 61 6c 70 68 61 62 |er (i.e.|, alphab|
|00003e40| 65 74 69 63 61 6c 29 2e | 20 54 68 65 20 73 75 62 |etical).| The sub|
|00003e50| 74 6c 65 0a 64 69 73 74 | 69 6e 63 74 69 6f 6e 20 |tle.dist|inction |
|00003e60| 62 65 74 77 65 65 6e 20 | 5c 63 6f 64 65 7b 22 6e |between |\code{"n|
|00003e70| 66 6c 22 7d 20 61 6e 64 | 20 5c 63 6f 64 65 7b 22 |fl"} and| \code{"|
|00003e80| 73 74 64 6e 61 6d 65 22 | 7d 20 69 73 20 74 68 61 |stdname"|} is tha|
|00003e90| 74 20 74 68 65 0a 73 74 | 61 6e 64 61 72 64 20 6e |t the.st|andard n|
|00003ea0| 61 6d 65 20 69 73 20 61 | 20 73 6f 72 74 20 6f 66 |ame is a| sort of|
|00003eb0| 20 74 68 65 20 6e 61 6d | 65 20 61 73 20 70 72 69 | the nam|e as pri|
|00003ec0| 6e 74 65 64 2c 20 77 68 | 69 63 68 20 6d 65 61 6e |nted, wh|ich mean|
|00003ed0| 73 20 74 68 61 74 20 74 | 68 65 0a 65 6d 62 65 64 |s that t|he.embed|
|00003ee0| 64 65 64 20 6c 69 6e 65 | 20 6e 75 6d 62 65 72 73 |ded line| numbers|
|00003ef0| 20 67 65 74 20 63 6f 6d | 70 61 72 65 64 20 69 6e | get com|pared in|
|00003f00| 20 61 6e 20 6f 64 64 20 | 77 61 79 2e 20 20 46 6f | an odd |way. Fo|
|00003f10| 72 20 65 78 61 6d 70 6c | 65 2c 20 6c 69 6e 65 73 |r exampl|e, lines|
|00003f20| 0a 33 2c 20 32 30 2c 20 | 61 6e 64 20 34 30 20 77 |.3, 20, |and 40 w|
|00003f30| 6f 75 6c 64 20 28 69 66 | 20 74 68 65 20 66 69 6c |ould (if| the fil|
|00003f40| 65 20 6e 61 6d 65 73 20 | 77 65 72 65 20 74 68 65 |e names |were the|
|00003f50| 20 73 61 6d 65 29 20 61 | 70 70 65 61 72 20 69 6e | same) a|ppear in|
|00003f60| 20 74 68 65 0a 73 74 72 | 69 6e 67 20 6f 72 64 65 | the.str|ing orde|
|00003f70| 72 20 32 30 2c 20 33 20 | 61 6e 64 20 34 30 2e 20 |r 20, 3 |and 40. |
|00003f80| 20 49 6e 20 63 6f 6e 74 | 72 61 73 74 2c 20 5c 63 | In cont|rast, \c|
|00003f90| 6f 64 65 7b 22 6e 66 6c | 22 7d 20 64 6f 65 73 20 |ode{"nfl|"} does |
|00003fa0| 61 20 6e 75 6d 65 72 69 | 63 0a 63 6f 6d 70 61 72 |a numeri|c.compar|
|00003fb0| 65 20 6f 66 20 74 68 65 | 20 6c 69 6e 65 20 6e 75 |e of the| line nu|
|00003fc0| 6d 62 65 72 73 2e 20 20 | 49 6e 20 66 61 63 74 2c |mbers. |In fact,|
|00003fd0| 20 5c 63 6f 64 65 7b 73 | 6f 72 74 5f 73 74 61 74 | \code{s|ort_stat|
|00003fe0| 73 28 22 6e 66 6c 22 29 | 7d 20 69 73 20 74 68 65 |s("nfl")|} is the|
|00003ff0| 0a 73 61 6d 65 20 61 73 | 20 5c 63 6f 64 65 7b 73 |.same as| \code{s|
|00004000| 6f 72 74 5f 73 74 61 74 | 73 28 22 6e 61 6d 65 22 |ort_stat|s("name"|
|00004010| 2c 20 22 66 69 6c 65 22 | 2c 20 22 6c 69 6e 65 22 |, "file"|, "line"|
|00004020| 29 7d 2e 0a 0a 46 6f 72 | 20 63 6f 6d 70 61 74 69 |)}...For| compati|
|00004030| 62 69 6c 69 74 79 20 77 | 69 74 68 20 74 68 65 20 |bility w|ith the |
|00004040| 6f 6c 64 20 70 72 6f 66 | 69 6c 65 72 2c 20 74 68 |old prof|iler, th|
|00004050| 65 20 6e 75 6d 65 72 69 | 63 20 61 72 67 75 6d 65 |e numeri|c argume|
|00004060| 6e 74 73 0a 5c 73 61 6d | 70 7b 2d 31 7d 2c 20 5c |nts.\sam|p{-1}, \|
|00004070| 73 61 6d 70 7b 30 7d 2c | 20 5c 73 61 6d 70 7b 31 |samp{0},| \samp{1|
|00004080| 7d 2c 20 61 6e 64 20 5c | 73 61 6d 70 7b 32 7d 20 |}, and \|samp{2} |
|00004090| 61 72 65 20 70 65 72 6d | 69 74 74 65 64 2e 20 20 |are perm|itted. |
|000040a0| 54 68 65 79 20 61 72 65 | 0a 69 6e 74 65 72 70 72 |They are|.interpr|
|000040b0| 65 74 65 64 20 61 73 20 | 5c 63 6f 64 65 7b 22 73 |eted as |\code{"s|
|000040c0| 74 64 6e 61 6d 65 22 7d | 2c 20 5c 63 6f 64 65 7b |tdname"}|, \code{|
|000040d0| 22 63 61 6c 6c 73 22 7d | 2c 20 5c 63 6f 64 65 7b |"calls"}|, \code{|
|000040e0| 22 74 69 6d 65 22 7d 2c | 20 61 6e 64 0a 5c 63 6f |"time"},| and.\co|
|000040f0| 64 65 7b 22 63 75 6d 75 | 6c 61 74 69 76 65 22 7d |de{"cumu|lative"}|
|00004100| 20 72 65 73 70 65 63 74 | 69 76 65 6c 79 2e 20 20 | respect|ively. |
|00004110| 49 66 20 74 68 69 73 20 | 6f 6c 64 20 73 74 79 6c |If this |old styl|
|00004120| 65 20 66 6f 72 6d 61 74 | 20 28 6e 75 6d 65 72 69 |e format| (numeri|
|00004130| 63 29 0a 69 73 20 75 73 | 65 64 2c 20 6f 6e 6c 79 |c).is us|ed, only|
|00004140| 20 6f 6e 65 20 73 6f 72 | 74 20 6b 65 79 20 28 74 | one sor|t key (t|
|00004150| 68 65 20 6e 75 6d 65 72 | 69 63 20 6b 65 79 29 20 |he numer|ic key) |
|00004160| 77 69 6c 6c 20 62 65 20 | 75 73 65 64 2c 20 61 6e |will be |used, an|
|00004170| 64 0a 61 64 64 69 74 69 | 6f 6e 61 6c 20 61 72 67 |d.additi|onal arg|
|00004180| 75 6d 65 6e 74 73 20 77 | 69 6c 6c 20 62 65 20 73 |uments w|ill be s|
|00004190| 69 6c 65 6e 74 6c 79 20 | 69 67 6e 6f 72 65 64 2e |ilently |ignored.|
|000041a0| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|000041b0| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000041c0| 63 7d 7b 72 65 76 65 72 | 73 65 5f 6f 72 64 65 72 |c}{rever|se_order|
|000041d0| 7d 7b 7d 0a 54 68 69 73 | 20 6d 65 74 68 6f 64 20 |}{}.This| method |
|000041e0| 66 6f 72 20 74 68 65 20 | 5c 63 6f 64 65 7b 53 74 |for the |\code{St|
|000041f0| 61 74 73 7d 20 63 6c 61 | 73 73 20 72 65 76 65 72 |ats} cla|ss rever|
|00004200| 73 65 73 20 74 68 65 20 | 6f 72 64 65 72 69 6e 67 |ses the |ordering|
|00004210| 20 6f 66 20 74 68 65 20 | 62 61 73 69 63 0a 6c 69 | of the |basic.li|
|00004220| 73 74 20 77 69 74 68 69 | 6e 20 74 68 65 20 6f 62 |st withi|n the ob|
|00004230| 6a 65 63 74 2e 20 20 54 | 68 69 73 20 6d 65 74 68 |ject. T|his meth|
|00004240| 6f 64 20 69 73 20 70 72 | 6f 76 69 64 65 64 20 70 |od is pr|ovided p|
|00004250| 72 69 6d 61 72 69 6c 79 | 20 66 6f 72 0a 63 6f 6d |rimarily| for.com|
|00004260| 70 61 74 69 62 69 6c 69 | 74 79 20 77 69 74 68 20 |patibili|ty with |
|00004270| 74 68 65 20 6f 6c 64 20 | 70 72 6f 66 69 6c 65 72 |the old |profiler|
|00004280| 2e 20 20 49 74 73 20 75 | 74 69 6c 69 74 79 20 69 |. Its u|tility i|
|00004290| 73 20 71 75 65 73 74 69 | 6f 6e 61 62 6c 65 0a 6e |s questi|onable.n|
|000042a0| 6f 77 20 74 68 61 74 20 | 61 73 63 65 6e 64 69 6e |ow that |ascendin|
|000042b0| 67 20 76 73 20 64 65 73 | 63 65 6e 64 69 6e 67 20 |g vs des|cending |
|000042c0| 6f 72 64 65 72 20 69 73 | 20 70 72 6f 70 65 72 6c |order is| properl|
|000042d0| 79 20 73 65 6c 65 63 74 | 65 64 20 62 61 73 65 64 |y select|ed based|
|000042e0| 20 6f 6e 0a 74 68 65 20 | 73 6f 72 74 20 6b 65 79 | on.the |sort key|
|000042f0| 20 6f 66 20 63 68 6f 69 | 63 65 2e 0a 5c 65 6e 64 | of choi|ce..\end|
|00004300| 7b 66 75 6e 63 64 65 73 | 63 7d 0a 0a 5c 62 65 67 |{funcdes|c}..\beg|
|00004310| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 70 72 69 |in{funcd|esc}{pri|
|00004320| 6e 74 5f 73 74 61 74 73 | 7d 7b 72 65 73 74 72 69 |nt_stats|}{restri|
|00004330| 63 74 69 6f 6e 5c 6f 70 | 74 69 6f 6e 61 6c 7b 5c |ction\op|tional{\|
|00004340| 2c 20 2e 2e 2e 7d 7d 0a | 54 68 69 73 20 6d 65 74 |, ...}}.|This met|
|00004350| 68 6f 64 20 66 6f 72 20 | 74 68 65 20 5c 63 6f 64 |hod for |the \cod|
|00004360| 65 7b 53 74 61 74 73 7d | 20 63 6c 61 73 73 20 70 |e{Stats}| class p|
|00004370| 72 69 6e 74 73 20 6f 75 | 74 20 61 20 72 65 70 6f |rints ou|t a repo|
|00004380| 72 74 20 61 73 20 64 65 | 73 63 72 69 62 65 64 0a |rt as de|scribed.|
|00004390| 69 6e 20 74 68 65 20 5c | 63 6f 64 65 7b 70 72 6f |in the \|code{pro|
|000043a0| 66 69 6c 65 2e 72 75 6e | 28 29 7d 20 64 65 66 69 |file.run|()} defi|
|000043b0| 6e 69 74 69 6f 6e 2e 0a | 0a 54 68 65 20 6f 72 64 |nition..|.The ord|
|000043c0| 65 72 20 6f 66 20 74 68 | 65 20 70 72 69 6e 74 69 |er of th|e printi|
|000043d0| 6e 67 20 69 73 20 62 61 | 73 65 64 20 6f 6e 20 74 |ng is ba|sed on t|
|000043e0| 68 65 20 6c 61 73 74 20 | 5c 63 6f 64 65 7b 73 6f |he last |\code{so|
|000043f0| 72 74 5f 73 74 61 74 73 | 28 29 7d 0a 6f 70 65 72 |rt_stats|()}.oper|
|00004400| 61 74 69 6f 6e 20 64 6f | 6e 65 20 6f 6e 20 74 68 |ation do|ne on th|
|00004410| 65 20 6f 62 6a 65 63 74 | 20 28 73 75 62 6a 65 63 |e object| (subjec|
|00004420| 74 20 74 6f 20 63 61 76 | 65 61 74 73 20 69 6e 20 |t to cav|eats in |
|00004430| 5c 63 6f 64 65 7b 61 64 | 64 28 29 7d 20 61 6e 64 |\code{ad|d()} and|
|00004440| 0a 5c 63 6f 64 65 7b 73 | 74 72 69 70 5f 64 69 72 |.\code{s|trip_dir|
|00004450| 73 28 29 29 7d 2e 0a 0a | 54 68 65 20 61 72 67 75 |s())}...|The argu|
|00004460| 6d 65 6e 74 73 20 70 72 | 6f 76 69 64 65 64 20 28 |ments pr|ovided (|
|00004470| 69 66 20 61 6e 79 29 20 | 63 61 6e 20 62 65 20 75 |if any) |can be u|
|00004480| 73 65 64 20 74 6f 20 6c | 69 6d 69 74 20 74 68 65 |sed to l|imit the|
|00004490| 20 6c 69 73 74 20 64 6f | 77 6e 20 74 6f 0a 74 68 | list do|wn to.th|
|000044a0| 65 20 73 69 67 6e 69 66 | 69 63 61 6e 74 20 65 6e |e signif|icant en|
|000044b0| 74 72 69 65 73 2e 20 20 | 49 6e 69 74 69 61 6c 6c |tries. |Initiall|
|000044c0| 79 2c 20 74 68 65 20 6c | 69 73 74 20 69 73 20 74 |y, the l|ist is t|
|000044d0| 61 6b 65 6e 20 74 6f 20 | 62 65 20 74 68 65 0a 63 |aken to |be the.c|
|000044e0| 6f 6d 70 6c 65 74 65 20 | 73 65 74 20 6f 66 20 70 |omplete |set of p|
|000044f0| 72 6f 66 69 6c 65 64 20 | 66 75 6e 63 74 69 6f 6e |rofiled |function|
|00004500| 73 2e 20 20 45 61 63 68 | 20 72 65 73 74 72 69 63 |s. Each| restric|
|00004510| 74 69 6f 6e 20 69 73 20 | 65 69 74 68 65 72 20 61 |tion is |either a|
|00004520| 6e 0a 69 6e 74 65 67 65 | 72 20 28 74 6f 20 73 65 |n.intege|r (to se|
|00004530| 6c 65 63 74 20 61 20 63 | 6f 75 6e 74 20 6f 66 20 |lect a c|ount of |
|00004540| 6c 69 6e 65 73 29 2c 20 | 6f 72 20 61 20 64 65 63 |lines), |or a dec|
|00004550| 69 6d 61 6c 20 66 72 61 | 63 74 69 6f 6e 20 62 65 |imal fra|ction be|
|00004560| 74 77 65 65 6e 0a 30 2e | 30 20 61 6e 64 20 31 2e |tween.0.|0 and 1.|
|00004570| 30 20 69 6e 63 6c 75 73 | 69 76 65 20 28 74 6f 20 |0 inclus|ive (to |
|00004580| 73 65 6c 65 63 74 20 61 | 20 70 65 72 63 65 6e 74 |select a| percent|
|00004590| 61 67 65 20 6f 66 20 6c | 69 6e 65 73 29 2c 20 6f |age of l|ines), o|
|000045a0| 72 20 61 20 72 65 67 75 | 6c 61 72 0a 65 78 70 72 |r a regu|lar.expr|
|000045b0| 65 73 73 69 6f 6e 20 28 | 74 6f 20 70 61 74 74 65 |ession (|to patte|
|000045c0| 72 6e 20 6d 61 74 63 68 | 20 74 68 65 20 73 74 61 |rn match| the sta|
|000045d0| 6e 64 61 72 64 20 6e 61 | 6d 65 20 74 68 61 74 20 |ndard na|me that |
|000045e0| 69 73 20 70 72 69 6e 74 | 65 64 29 2e 20 20 49 66 |is print|ed). If|
|000045f0| 0a 73 65 76 65 72 61 6c | 20 72 65 73 74 72 69 63 |.several| restric|
|00004600| 74 69 6f 6e 73 20 61 72 | 65 20 70 72 6f 76 69 64 |tions ar|e provid|
|00004610| 65 64 2c 20 74 68 65 6e | 20 74 68 65 79 20 61 72 |ed, then| they ar|
|00004620| 65 20 61 70 70 6c 69 65 | 64 20 73 65 71 75 65 6e |e applie|d sequen|
|00004630| 74 69 61 6c 6c 79 2e 0a | 46 6f 72 20 65 78 61 6d |tially..|For exam|
|00004640| 70 6c 65 3a 0a 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |ple:..\b|egin{ver|
|00004650| 62 61 74 69 6d 7d 0a 20 | 20 20 20 70 72 69 6e 74 |batim}. | print|
|00004660| 5f 73 74 61 74 73 28 2e | 31 2c 20 22 66 6f 6f 3a |_stats(.|1, "foo:|
|00004670| 22 29 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |").\end{|verbatim|
|00004680| 7d 0a 0a 77 6f 75 6c 64 | 20 66 69 72 73 74 20 6c |}..would| first l|
|00004690| 69 6d 69 74 20 74 68 65 | 20 70 72 69 6e 74 69 6e |imit the| printin|
|000046a0| 67 20 74 6f 20 66 69 72 | 73 74 20 31 30 5c 25 20 |g to fir|st 10\% |
|000046b0| 6f 66 20 6c 69 73 74 2c | 20 61 6e 64 20 74 68 65 |of list,| and the|
|000046c0| 6e 20 6f 6e 6c 79 0a 70 | 72 69 6e 74 20 66 75 6e |n only.p|rint fun|
|000046d0| 63 74 69 6f 6e 73 20 74 | 68 61 74 20 77 65 72 65 |ctions t|hat were|
|000046e0| 20 70 61 72 74 20 6f 66 | 20 66 69 6c 65 6e 61 6d | part of| filenam|
|000046f0| 65 20 5c 73 61 6d 70 7b | 2e 2a 66 6f 6f 3a 7d 2e |e \samp{|.*foo:}.|
|00004700| 20 20 49 6e 0a 63 6f 6e | 74 72 61 73 74 2c 20 74 | In.con|trast, t|
|00004710| 68 65 20 63 6f 6d 6d 61 | 6e 64 3a 0a 0a 5c 62 65 |he comma|nd:..\be|
|00004720| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0a 20 20 |gin{verb|atim}. |
|00004730| 20 20 70 72 69 6e 74 5f | 73 74 61 74 73 28 22 66 | print_|stats("f|
|00004740| 6f 6f 3a 22 2c 20 2e 31 | 29 0a 5c 65 6e 64 7b 76 |oo:", .1|).\end{v|
|00004750| 65 72 62 61 74 69 6d 7d | 0a 0a 77 6f 75 6c 64 20 |erbatim}|..would |
|00004760| 6c 69 6d 69 74 20 74 68 | 65 20 6c 69 73 74 20 74 |limit th|e list t|
|00004770| 6f 20 61 6c 6c 20 66 75 | 6e 63 74 69 6f 6e 73 20 |o all fu|nctions |
|00004780| 68 61 76 69 6e 67 20 66 | 69 6c 65 20 6e 61 6d 65 |having f|ile name|
|00004790| 73 20 5c 73 61 6d 70 7b | 2e 2a 66 6f 6f 3a 7d 2c |s \samp{|.*foo:},|
|000047a0| 0a 61 6e 64 20 74 68 65 | 6e 20 70 72 6f 63 65 65 |.and the|n procee|
|000047b0| 64 20 74 6f 20 6f 6e 6c | 79 20 70 72 69 6e 74 20 |d to onl|y print |
|000047c0| 74 68 65 20 66 69 72 73 | 74 20 31 30 5c 25 20 6f |the firs|t 10\% o|
|000047d0| 66 20 74 68 65 6d 2e 0a | 5c 65 6e 64 7b 66 75 6e |f them..|\end{fun|
|000047e0| 63 64 65 73 63 7d 0a 0a | 0a 5c 62 65 67 69 6e 7b |cdesc}..|.\begin{|
|000047f0| 66 75 6e 63 64 65 73 63 | 7d 7b 70 72 69 6e 74 5f |funcdesc|}{print_|
|00004800| 63 61 6c 6c 65 72 73 7d | 7b 72 65 73 74 72 69 63 |callers}|{restric|
|00004810| 74 69 6f 6e 73 5c 6f 70 | 74 69 6f 6e 61 6c 7b 5c |tions\op|tional{\|
|00004820| 2c 20 2e 2e 2e 7d 7d 0a | 54 68 69 73 20 6d 65 74 |, ...}}.|This met|
|00004830| 68 6f 64 20 66 6f 72 20 | 74 68 65 20 5c 63 6f 64 |hod for |the \cod|
|00004840| 65 7b 53 74 61 74 73 7d | 20 63 6c 61 73 73 20 70 |e{Stats}| class p|
|00004850| 72 69 6e 74 73 20 61 20 | 6c 69 73 74 20 6f 66 20 |rints a |list of |
|00004860| 61 6c 6c 20 66 75 6e 63 | 74 69 6f 6e 73 0a 74 68 |all func|tions.th|
|00004870| 61 74 20 63 61 6c 6c 65 | 64 20 65 61 63 68 20 66 |at calle|d each f|
|00004880| 75 6e 63 74 69 6f 6e 20 | 69 6e 20 74 68 65 20 70 |unction |in the p|
|00004890| 72 6f 66 69 6c 65 64 20 | 64 61 74 61 62 61 73 65 |rofiled |database|
|000048a0| 2e 20 20 54 68 65 20 6f | 72 64 65 72 69 6e 67 20 |. The o|rdering |
|000048b0| 69 73 0a 69 64 65 6e 74 | 69 63 61 6c 20 74 6f 20 |is.ident|ical to |
|000048c0| 74 68 61 74 20 70 72 6f | 76 69 64 65 64 20 62 79 |that pro|vided by|
|000048d0| 20 5c 63 6f 64 65 7b 70 | 72 69 6e 74 5f 73 74 61 | \code{p|rint_sta|
|000048e0| 74 73 28 29 7d 2c 20 61 | 6e 64 20 74 68 65 20 64 |ts()}, a|nd the d|
|000048f0| 65 66 69 6e 69 74 69 6f | 6e 0a 6f 66 20 74 68 65 |efinitio|n.of the|
|00004900| 20 72 65 73 74 72 69 63 | 74 69 6e 67 20 61 72 67 | restric|ting arg|
|00004910| 75 6d 65 6e 74 20 69 73 | 20 61 6c 73 6f 20 69 64 |ument is| also id|
|00004920| 65 6e 74 69 63 61 6c 2e | 20 20 46 6f 72 20 63 6f |entical.| For co|
|00004930| 6e 76 65 6e 69 65 6e 63 | 65 2c 20 61 0a 6e 75 6d |nvenienc|e, a.num|
|00004940| 62 65 72 20 69 73 20 73 | 68 6f 77 6e 20 69 6e 20 |ber is s|hown in |
|00004950| 70 61 72 65 6e 74 68 65 | 73 65 73 20 61 66 74 65 |parenthe|ses afte|
|00004960| 72 20 65 61 63 68 20 63 | 61 6c 6c 65 72 20 74 6f |r each c|aller to|
|00004970| 20 73 68 6f 77 20 68 6f | 77 20 6d 61 6e 79 0a 74 | show ho|w many.t|
|00004980| 69 6d 65 73 20 74 68 69 | 73 20 73 70 65 63 69 66 |imes thi|s specif|
|00004990| 69 63 20 63 61 6c 6c 20 | 77 61 73 20 6d 61 64 65 |ic call |was made|
|000049a0| 2e 20 20 41 20 73 65 63 | 6f 6e 64 20 6e 6f 6e 2d |. A sec|ond non-|
|000049b0| 70 61 72 65 6e 74 68 65 | 73 69 7a 65 64 20 6e 75 |parenthe|sized nu|
|000049c0| 6d 62 65 72 0a 69 73 20 | 74 68 65 20 63 75 6d 75 |mber.is |the cumu|
|000049d0| 6c 61 74 69 76 65 20 74 | 69 6d 65 20 73 70 65 6e |lative t|ime spen|
|000049e0| 74 20 69 6e 20 74 68 65 | 20 66 75 6e 63 74 69 6f |t in the| functio|
|000049f0| 6e 20 61 74 20 74 68 65 | 20 72 69 67 68 74 2e 0a |n at the| right..|
|00004a00| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|00004a10| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00004a20| 7b 70 72 69 6e 74 5f 63 | 61 6c 6c 65 65 73 7d 7b |{print_c|allees}{|
|00004a30| 72 65 73 74 72 69 63 74 | 69 6f 6e 73 5c 6f 70 74 |restrict|ions\opt|
|00004a40| 69 6f 6e 61 6c 7b 5c 2c | 20 2e 2e 2e 7d 7d 0a 54 |ional{\,| ...}}.T|
|00004a50| 68 69 73 20 6d 65 74 68 | 6f 64 20 66 6f 72 20 74 |his meth|od for t|
|00004a60| 68 65 20 5c 63 6f 64 65 | 7b 53 74 61 74 73 7d 20 |he \code|{Stats} |
|00004a70| 63 6c 61 73 73 20 70 72 | 69 6e 74 73 20 61 20 6c |class pr|ints a l|
|00004a80| 69 73 74 20 6f 66 20 61 | 6c 6c 20 66 75 6e 63 74 |ist of a|ll funct|
|00004a90| 69 6f 6e 0a 74 68 61 74 | 20 77 65 72 65 20 63 61 |ion.that| were ca|
|00004aa0| 6c 6c 65 64 20 62 79 20 | 74 68 65 20 69 6e 64 69 |lled by |the indi|
|00004ab0| 63 61 74 65 64 20 66 75 | 6e 63 74 69 6f 6e 2e 20 |cated fu|nction. |
|00004ac0| 20 41 73 69 64 65 20 66 | 72 6f 6d 20 74 68 69 73 | Aside f|rom this|
|00004ad0| 20 72 65 76 65 72 73 61 | 6c 0a 6f 66 20 64 69 72 | reversa|l.of dir|
|00004ae0| 65 63 74 69 6f 6e 20 6f | 66 20 63 61 6c 6c 73 20 |ection o|f calls |
|00004af0| 28 72 65 3a 20 63 61 6c | 6c 65 64 20 76 73 20 77 |(re: cal|led vs w|
|00004b00| 61 73 20 63 61 6c 6c 65 | 64 20 62 79 29 2c 20 74 |as calle|d by), t|
|00004b10| 68 65 20 61 72 67 75 6d | 65 6e 74 73 20 61 6e 64 |he argum|ents and|
|00004b20| 0a 6f 72 64 65 72 69 6e | 67 20 61 72 65 20 69 64 |.orderin|g are id|
|00004b30| 65 6e 74 69 63 61 6c 20 | 74 6f 20 74 68 65 20 5c |entical |to the \|
|00004b40| 63 6f 64 65 7b 70 72 69 | 6e 74 5f 63 61 6c 6c 65 |code{pri|nt_calle|
|00004b50| 72 73 28 29 7d 20 6d 65 | 74 68 6f 64 2e 0a 5c 65 |rs()} me|thod..\e|
|00004b60| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0a 0a 5c 62 |nd{funcd|esc}..\b|
|00004b70| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 69 |egin{fun|cdesc}{i|
|00004b80| 67 6e 6f 72 65 7d 7b 7d | 0a 54 68 69 73 20 6d 65 |gnore}{}|.This me|
|00004b90| 74 68 6f 64 20 6f 66 20 | 74 68 65 20 5c 63 6f 64 |thod of |the \cod|
|00004ba0| 65 7b 53 74 61 74 73 7d | 20 63 6c 61 73 73 20 69 |e{Stats}| class i|
|00004bb0| 73 20 75 73 65 64 20 74 | 6f 20 64 69 73 70 6f 73 |s used t|o dispos|
|00004bc0| 65 20 6f 66 20 74 68 65 | 20 76 61 6c 75 65 0a 72 |e of the| value.r|
|00004bd0| 65 74 75 72 6e 65 64 20 | 62 79 20 65 61 72 6c 69 |eturned |by earli|
|00004be0| 65 72 20 6d 65 74 68 6f | 64 73 2e 20 20 41 6c 6c |er metho|ds. All|
|00004bf0| 20 73 74 61 6e 64 61 72 | 64 20 6d 65 74 68 6f 64 | standar|d method|
|00004c00| 73 20 69 6e 20 74 68 69 | 73 20 63 6c 61 73 73 0a |s in thi|s class.|
|00004c10| 72 65 74 75 72 6e 20 74 | 68 65 20 69 6e 73 74 61 |return t|he insta|
|00004c20| 6e 63 65 20 74 68 61 74 | 20 69 73 20 62 65 69 6e |nce that| is bein|
|00004c30| 67 20 70 72 6f 63 65 73 | 73 65 64 2c 20 73 6f 20 |g proces|sed, so |
|00004c40| 74 68 61 74 20 74 68 65 | 20 63 6f 6d 6d 61 6e 64 |that the| command|
|00004c50| 73 20 63 61 6e 0a 62 65 | 20 73 74 72 75 6e 67 20 |s can.be| strung |
|00004c60| 74 6f 67 65 74 68 65 72 | 2e 20 20 46 6f 72 20 65 |together|. For e|
|00004c70| 78 61 6d 70 6c 65 3a 0a | 0a 5c 62 65 67 69 6e 7b |xample:.|.\begin{|
|00004c80| 76 65 72 62 61 74 69 6d | 7d 0a 70 73 74 61 74 73 |verbatim|}.pstats|
|00004c90| 2e 53 74 61 74 73 28 27 | 66 6f 6f 66 69 6c 65 27 |.Stats('|foofile'|
|00004ca0| 29 2e 73 74 72 69 70 5f | 64 69 72 73 28 29 2e 73 |).strip_|dirs().s|
|00004cb0| 6f 72 74 5f 73 74 61 74 | 73 28 27 63 75 6d 27 29 |ort_stat|s('cum')|
|00004cc0| 20 5c 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | \. | |
|00004cd0| 20 20 20 20 20 20 20 20 | 20 20 2e 70 72 69 6e 74 | | .print|
|00004ce0| 5f 73 74 61 74 73 28 29 | 2e 69 67 6e 6f 72 65 28 |_stats()|.ignore(|
|00004cf0| 29 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |).\end{v|erbatim}|
|00004d00| 0a 0a 77 6f 75 6c 64 20 | 70 65 72 66 6f 72 6d 20 |..would |perform |
|00004d10| 61 6c 6c 20 74 68 65 20 | 69 6e 64 69 63 61 74 65 |all the |indicate|
|00004d20| 64 20 66 75 6e 63 74 69 | 6f 6e 73 2c 20 62 75 74 |d functi|ons, but|
|00004d30| 20 69 74 20 77 6f 75 6c | 64 20 6e 6f 74 20 72 65 | it woul|d not re|
|00004d40| 74 75 72 6e 0a 74 68 65 | 20 66 69 6e 61 6c 20 72 |turn.the| final r|
|00004d50| 65 66 65 72 65 6e 63 65 | 20 74 6f 20 74 68 65 20 |eference| to the |
|00004d60| 5c 63 6f 64 65 7b 53 74 | 61 74 73 7d 20 69 6e 73 |\code{St|ats} ins|
|00004d70| 74 61 6e 63 65 2e 25 0a | 5c 66 6f 6f 74 6e 6f 74 |tance.%.|\footnot|
|00004d80| 65 7b 0a 54 68 69 73 20 | 77 61 73 20 6f 6e 63 65 |e{.This |was once|
|00004d90| 20 6e 65 63 65 73 73 61 | 72 79 2c 20 77 68 65 6e | necessa|ry, when|
|00004da0| 20 50 79 74 68 6f 6e 20 | 77 6f 75 6c 64 20 70 72 | Python |would pr|
|00004db0| 69 6e 74 20 61 6e 79 20 | 75 6e 75 73 65 64 20 65 |int any |unused e|
|00004dc0| 78 70 72 65 73 73 69 6f | 6e 0a 72 65 73 75 6c 74 |xpressio|n.result|
|00004dd0| 20 74 68 61 74 20 77 61 | 73 20 6e 6f 74 20 5c 63 | that wa|s not \c|
|00004de0| 6f 64 65 7b 4e 6f 6e 65 | 7d 2e 20 20 54 68 65 20 |ode{None|}. The |
|00004df0| 6d 65 74 68 6f 64 20 69 | 73 20 73 74 69 6c 6c 20 |method i|s still |
|00004e00| 64 65 66 69 6e 65 64 20 | 66 6f 72 0a 62 61 63 6b |defined |for.back|
|00004e10| 77 61 72 64 20 63 6f 6d | 70 61 74 69 62 69 6c 69 |ward com|patibili|
|00004e20| 74 79 2e 0a 7d 0a 5c 65 | 6e 64 7b 66 75 6e 63 64 |ty..}.\e|nd{funcd|
|00004e30| 65 73 63 7d 0a 0a 0a 5c | 73 65 63 74 69 6f 6e 7b |esc}...\|section{|
|00004e40| 4c 69 6d 69 74 61 74 69 | 6f 6e 73 7d 0a 0a 54 68 |Limitati|ons}..Th|
|00004e50| 65 72 65 20 61 72 65 20 | 74 77 6f 20 66 75 6e 64 |ere are |two fund|
|00004e60| 61 6d 65 6e 74 61 6c 20 | 6c 69 6d 69 74 61 74 69 |amental |limitati|
|00004e70| 6f 6e 73 20 6f 6e 20 74 | 68 69 73 20 70 72 6f 66 |ons on t|his prof|
|00004e80| 69 6c 65 72 2e 20 20 54 | 68 65 20 66 69 72 73 74 |iler. T|he first|
|00004e90| 20 69 73 0a 74 68 61 74 | 20 69 74 20 72 65 6c 69 | is.that| it reli|
|00004ea0| 65 73 20 6f 6e 20 74 68 | 65 20 50 79 74 68 6f 6e |es on th|e Python|
|00004eb0| 20 69 6e 74 65 72 70 72 | 65 74 65 72 20 74 6f 20 | interpr|eter to |
|00004ec0| 64 69 73 70 61 74 63 68 | 20 5c 64 66 6e 7b 63 61 |dispatch| \dfn{ca|
|00004ed0| 6c 6c 7d 2c 0a 5c 64 66 | 6e 7b 72 65 74 75 72 6e |ll},.\df|n{return|
|00004ee0| 7d 2c 20 61 6e 64 20 5c | 64 66 6e 7b 65 78 63 65 |}, and \|dfn{exce|
|00004ef0| 70 74 69 6f 6e 7d 20 65 | 76 65 6e 74 73 2e 20 20 |ption} e|vents. |
|00004f00| 43 6f 6d 70 69 6c 65 64 | 20 43 20 63 6f 64 65 20 |Compiled| C code |
|00004f10| 64 6f 65 73 20 6e 6f 74 | 0a 67 65 74 20 69 6e 74 |does not|.get int|
|00004f20| 65 72 70 72 65 74 65 64 | 2c 20 61 6e 64 20 68 65 |erpreted|, and he|
|00004f30| 6e 63 65 20 69 73 20 60 | 60 69 6e 76 69 73 69 62 |nce is `|`invisib|
|00004f40| 6c 65 27 27 20 74 6f 20 | 74 68 65 20 70 72 6f 66 |le'' to |the prof|
|00004f50| 69 6c 65 72 2e 20 20 41 | 6c 6c 20 74 69 6d 65 0a |iler. A|ll time.|
|00004f60| 73 70 65 6e 74 20 69 6e | 20 43 20 63 6f 64 65 20 |spent in| C code |
|00004f70| 28 69 6e 63 6c 75 64 69 | 6e 67 20 62 75 69 6c 74 |(includi|ng built|
|00004f80| 69 6e 20 66 75 6e 63 74 | 69 6f 6e 73 29 20 77 69 |in funct|ions) wi|
|00004f90| 6c 6c 20 62 65 20 63 68 | 61 72 67 65 64 20 74 6f |ll be ch|arged to|
|00004fa0| 20 74 68 65 0a 50 79 74 | 68 6f 6e 20 66 75 6e 63 | the.Pyt|hon func|
|00004fb0| 74 69 6f 6e 20 74 68 61 | 74 20 69 6e 76 6f 6b 65 |tion tha|t invoke|
|00004fc0| 64 20 74 68 65 20 43 20 | 63 6f 64 65 2e 20 20 49 |d the C |code. I|
|00004fd0| 66 20 74 68 65 20 43 20 | 63 6f 64 65 20 63 61 6c |f the C |code cal|
|00004fe0| 6c 73 20 6f 75 74 0a 74 | 6f 20 73 6f 6d 65 20 6e |ls out.t|o some n|
|00004ff0| 61 74 69 76 65 20 50 79 | 74 68 6f 6e 20 63 6f 64 |ative Py|thon cod|
|00005000| 65 2c 20 74 68 65 6e 20 | 74 68 6f 73 65 20 63 61 |e, then |those ca|
|00005010| 6c 6c 73 20 77 69 6c 6c | 20 62 65 20 70 72 6f 66 |lls will| be prof|
|00005020| 69 6c 65 64 0a 70 72 6f | 70 65 72 6c 79 2e 0a 0a |iled.pro|perly...|
|00005030| 54 68 65 20 73 65 63 6f | 6e 64 20 6c 69 6d 69 74 |The seco|nd limit|
|00005040| 61 74 69 6f 6e 20 68 61 | 73 20 74 6f 20 64 6f 20 |ation ha|s to do |
|00005050| 77 69 74 68 20 61 63 63 | 75 72 61 63 79 20 6f 66 |with acc|uracy of|
|00005060| 20 74 69 6d 69 6e 67 20 | 69 6e 66 6f 72 6d 61 74 | timing |informat|
|00005070| 69 6f 6e 2e 0a 54 68 65 | 72 65 20 69 73 20 61 20 |ion..The|re is a |
|00005080| 66 75 6e 64 61 6d 65 6e | 74 61 6c 20 70 72 6f 62 |fundamen|tal prob|
|00005090| 6c 65 6d 20 77 69 74 68 | 20 64 65 74 65 72 6d 69 |lem with| determi|
|000050a0| 6e 69 73 74 69 63 20 70 | 72 6f 66 69 6c 65 72 73 |nistic p|rofilers|
|000050b0| 20 69 6e 76 6f 6c 76 69 | 6e 67 0a 61 63 63 75 72 | involvi|ng.accur|
|000050c0| 61 63 79 2e 20 20 54 68 | 65 20 6d 6f 73 74 20 6f |acy. Th|e most o|
|000050d0| 62 76 69 6f 75 73 20 72 | 65 73 74 72 69 63 74 69 |bvious r|estricti|
|000050e0| 6f 6e 20 69 73 20 74 68 | 61 74 20 74 68 65 20 75 |on is th|at the u|
|000050f0| 6e 64 65 72 6c 79 69 6e | 67 20 60 60 63 6c 6f 63 |nderlyin|g ``cloc|
|00005100| 6b 27 27 0a 69 73 20 6f | 6e 6c 79 20 74 69 63 6b |k''.is o|nly tick|
|00005110| 69 6e 67 20 61 74 20 61 | 20 72 61 74 65 20 28 74 |ing at a| rate (t|
|00005120| 79 70 69 63 61 6c 6c 79 | 29 20 6f 66 20 61 62 6f |ypically|) of abo|
|00005130| 75 74 20 2e 30 30 31 20 | 73 65 63 6f 6e 64 73 2e |ut .001 |seconds.|
|00005140| 20 20 48 65 6e 63 65 20 | 6e 6f 0a 6d 65 61 73 75 | Hence |no.measu|
|00005150| 72 65 6d 65 6e 74 73 20 | 77 69 6c 6c 20 62 65 20 |rements |will be |
|00005160| 6d 6f 72 65 20 61 63 63 | 75 72 61 74 65 20 74 68 |more acc|urate th|
|00005170| 61 74 20 74 68 61 74 20 | 75 6e 64 65 72 6c 79 69 |at that |underlyi|
|00005180| 6e 67 20 63 6c 6f 63 6b | 2e 20 20 49 66 0a 65 6e |ng clock|. If.en|
|00005190| 6f 75 67 68 20 6d 65 61 | 73 75 72 65 6d 65 6e 74 |ough mea|surement|
|000051a0| 73 20 61 72 65 20 74 61 | 6b 65 6e 2c 20 74 68 65 |s are ta|ken, the|
|000051b0| 6e 20 74 68 65 20 60 60 | 65 72 72 6f 72 27 27 20 |n the ``|error'' |
|000051c0| 77 69 6c 6c 20 74 65 6e | 64 20 74 6f 20 61 76 65 |will ten|d to ave|
|000051d0| 72 61 67 65 0a 6f 75 74 | 2e 20 55 6e 66 6f 72 74 |rage.out|. Unfort|
|000051e0| 75 6e 61 74 65 6c 79 2c | 20 72 65 6d 6f 76 69 6e |unately,| removin|
|000051f0| 67 20 74 68 69 73 20 66 | 69 72 73 74 20 65 72 72 |g this f|irst err|
|00005200| 6f 72 20 69 6e 64 75 63 | 65 73 20 61 20 73 65 63 |or induc|es a sec|
|00005210| 6f 6e 64 20 73 6f 75 72 | 63 65 0a 6f 66 20 65 72 |ond sour|ce.of er|
|00005220| 72 6f 72 2e 2e 2e 0a 0a | 54 68 65 20 73 65 63 6f |ror.....|The seco|
|00005230| 6e 64 20 70 72 6f 62 6c | 65 6d 20 69 73 20 74 68 |nd probl|em is th|
|00005240| 61 74 20 69 74 20 60 60 | 74 61 6b 65 73 20 61 20 |at it ``|takes a |
|00005250| 77 68 69 6c 65 27 27 20 | 66 72 6f 6d 20 77 68 65 |while'' |from whe|
|00005260| 6e 20 61 6e 20 65 76 65 | 6e 74 20 69 73 0a 64 69 |n an eve|nt is.di|
|00005270| 73 70 61 74 63 68 65 64 | 20 75 6e 74 69 6c 20 74 |spatched| until t|
|00005280| 68 65 20 70 72 6f 66 69 | 6c 65 72 27 73 20 63 61 |he profi|ler's ca|
|00005290| 6c 6c 20 74 6f 20 67 65 | 74 20 74 68 65 20 74 69 |ll to ge|t the ti|
|000052a0| 6d 65 20 61 63 74 75 61 | 6c 6c 79 0a 5c 65 6d 70 |me actua|lly.\emp|
|000052b0| 68 7b 67 65 74 73 7d 20 | 74 68 65 20 73 74 61 74 |h{gets} |the stat|
|000052c0| 65 20 6f 66 20 74 68 65 | 20 63 6c 6f 63 6b 2e 20 |e of the| clock. |
|000052d0| 20 53 69 6d 69 6c 61 72 | 6c 79 2c 20 74 68 65 72 | Similar|ly, ther|
|000052e0| 65 20 69 73 20 61 20 63 | 65 72 74 61 69 6e 20 6c |e is a c|ertain l|
|000052f0| 61 67 0a 77 68 65 6e 20 | 65 78 69 74 69 6e 67 20 |ag.when |exiting |
|00005300| 74 68 65 20 70 72 6f 66 | 69 6c 65 72 20 65 76 65 |the prof|iler eve|
|00005310| 6e 74 20 68 61 6e 64 6c | 65 72 20 66 72 6f 6d 20 |nt handl|er from |
|00005320| 74 68 65 20 74 69 6d 65 | 20 74 68 61 74 20 74 68 |the time| that th|
|00005330| 65 20 63 6c 6f 63 6b 27 | 73 0a 76 61 6c 75 65 20 |e clock'|s.value |
|00005340| 77 61 73 20 6f 62 74 61 | 69 6e 65 64 20 28 61 6e |was obta|ined (an|
|00005350| 64 20 74 68 65 6e 20 73 | 71 75 69 72 72 65 6c 65 |d then s|quirrele|
|00005360| 64 20 61 77 61 79 29 2c | 20 75 6e 74 69 6c 20 74 |d away),| until t|
|00005370| 68 65 20 75 73 65 72 27 | 73 20 63 6f 64 65 0a 69 |he user'|s code.i|
|00005380| 73 20 6f 6e 63 65 20 61 | 67 61 69 6e 20 65 78 65 |s once a|gain exe|
|00005390| 63 75 74 69 6e 67 2e 20 | 20 41 73 20 61 20 72 65 |cuting. | As a re|
|000053a0| 73 75 6c 74 2c 20 66 75 | 6e 63 74 69 6f 6e 73 20 |sult, fu|nctions |
|000053b0| 74 68 61 74 20 61 72 65 | 20 63 61 6c 6c 65 64 20 |that are| called |
|000053c0| 6d 61 6e 79 0a 74 69 6d | 65 73 2c 20 6f 72 20 63 |many.tim|es, or c|
|000053d0| 61 6c 6c 20 6d 61 6e 79 | 20 66 75 6e 63 74 69 6f |all many| functio|
|000053e0| 6e 73 2c 20 77 69 6c 6c | 20 74 79 70 69 63 61 6c |ns, will| typical|
|000053f0| 6c 79 20 61 63 63 75 6d | 75 6c 61 74 65 20 74 68 |ly accum|ulate th|
|00005400| 69 73 20 65 72 72 6f 72 | 2e 0a 54 68 65 20 65 72 |is error|..The er|
|00005410| 72 6f 72 20 74 68 61 74 | 20 61 63 63 75 6d 75 6c |ror that| accumul|
|00005420| 61 74 65 73 20 69 6e 20 | 74 68 69 73 20 66 61 73 |ates in |this fas|
|00005430| 68 69 6f 6e 20 69 73 20 | 74 79 70 69 63 61 6c 6c |hion is |typicall|
|00005440| 79 20 6c 65 73 73 20 74 | 68 61 6e 20 74 68 65 0a |y less t|han the.|
|00005450| 61 63 63 75 72 61 63 79 | 20 6f 66 20 74 68 65 20 |accuracy| of the |
|00005460| 63 6c 6f 63 6b 20 28 69 | 2e 65 2e 2c 20 6c 65 73 |clock (i|.e., les|
|00005470| 73 20 74 68 61 6e 20 6f | 6e 65 20 63 6c 6f 63 6b |s than o|ne clock|
|00005480| 20 74 69 63 6b 29 2c 20 | 62 75 74 20 69 74 0a 5c | tick), |but it.\|
|00005490| 65 6d 70 68 7b 63 61 6e | 7d 20 61 63 63 75 6d 75 |emph{can|} accumu|
|000054a0| 6c 61 74 65 20 61 6e 64 | 20 62 65 63 6f 6d 65 20 |late and| become |
|000054b0| 76 65 72 79 20 73 69 67 | 6e 69 66 69 63 61 6e 74 |very sig|nificant|
|000054c0| 2e 20 20 54 68 69 73 20 | 70 72 6f 66 69 6c 65 72 |. This |profiler|
|000054d0| 0a 70 72 6f 76 69 64 65 | 73 20 61 20 6d 65 61 6e |.provide|s a mean|
|000054e0| 73 20 6f 66 20 63 61 6c | 69 62 72 61 74 69 6e 67 |s of cal|ibrating|
|000054f0| 20 69 74 73 65 6c 66 20 | 66 6f 72 20 61 20 67 69 | itself |for a gi|
|00005500| 76 65 6e 20 70 6c 61 74 | 66 6f 72 6d 20 73 6f 20 |ven plat|form so |
|00005510| 74 68 61 74 0a 74 68 69 | 73 20 65 72 72 6f 72 20 |that.thi|s error |
|00005520| 63 61 6e 20 62 65 20 70 | 72 6f 62 61 62 69 6c 69 |can be p|robabili|
|00005530| 73 74 69 63 61 6c 6c 79 | 20 28 69 2e 65 2e 2c 20 |stically| (i.e., |
|00005540| 6f 6e 20 74 68 65 20 61 | 76 65 72 61 67 65 29 20 |on the a|verage) |
|00005550| 72 65 6d 6f 76 65 64 2e | 0a 41 66 74 65 72 20 74 |removed.|.After t|
|00005560| 68 65 20 70 72 6f 66 69 | 6c 65 72 20 69 73 20 63 |he profi|ler is c|
|00005570| 61 6c 69 62 72 61 74 65 | 64 2c 20 69 74 20 77 69 |alibrate|d, it wi|
|00005580| 6c 6c 20 62 65 20 6d 6f | 72 65 20 61 63 63 75 72 |ll be mo|re accur|
|00005590| 61 74 65 20 28 69 6e 20 | 61 20 6c 65 61 73 74 0a |ate (in |a least.|
|000055a0| 73 71 75 61 72 65 20 73 | 65 6e 73 65 29 2c 20 62 |square s|ense), b|
|000055b0| 75 74 20 69 74 20 77 69 | 6c 6c 20 73 6f 6d 65 74 |ut it wi|ll somet|
|000055c0| 69 6d 65 73 20 70 72 6f | 64 75 63 65 20 6e 65 67 |imes pro|duce neg|
|000055d0| 61 74 69 76 65 20 6e 75 | 6d 62 65 72 73 20 28 77 |ative nu|mbers (w|
|000055e0| 68 65 6e 0a 63 61 6c 6c | 20 63 6f 75 6e 74 73 20 |hen.call| counts |
|000055f0| 61 72 65 20 65 78 63 65 | 70 74 69 6f 6e 61 6c 6c |are exce|ptionall|
|00005600| 79 20 6c 6f 77 2c 20 61 | 6e 64 20 74 68 65 20 67 |y low, a|nd the g|
|00005610| 6f 64 73 20 6f 66 20 70 | 72 6f 62 61 62 69 6c 69 |ods of p|robabili|
|00005620| 74 79 20 77 6f 72 6b 0a | 61 67 61 69 6e 73 74 20 |ty work.|against |
|00005630| 79 6f 75 20 3a 2d 29 2e | 20 29 20 20 44 6f 20 5c |you :-).| ) Do \|
|00005640| 65 6d 70 68 7b 4e 4f 54 | 7d 20 62 65 20 61 6c 61 |emph{NOT|} be ala|
|00005650| 72 6d 65 64 20 62 79 20 | 6e 65 67 61 74 69 76 65 |rmed by |negative|
|00005660| 20 6e 75 6d 62 65 72 73 | 20 69 6e 0a 74 68 65 20 | numbers| in.the |
|00005670| 70 72 6f 66 69 6c 65 2e | 20 20 54 68 65 79 20 73 |profile.| They s|
|00005680| 68 6f 75 6c 64 20 5c 65 | 6d 70 68 7b 6f 6e 6c 79 |hould \e|mph{only|
|00005690| 7d 20 61 70 70 65 61 72 | 20 69 66 20 79 6f 75 20 |} appear| if you |
|000056a0| 68 61 76 65 20 63 61 6c | 69 62 72 61 74 65 64 0a |have cal|ibrated.|
|000056b0| 79 6f 75 72 20 70 72 6f | 66 69 6c 65 72 2c 20 61 |your pro|filer, a|
|000056c0| 6e 64 20 74 68 65 20 72 | 65 73 75 6c 74 73 20 61 |nd the r|esults a|
|000056d0| 72 65 20 61 63 74 75 61 | 6c 6c 79 20 62 65 74 74 |re actua|lly bett|
|000056e0| 65 72 20 74 68 61 6e 20 | 77 69 74 68 6f 75 74 0a |er than |without.|
|000056f0| 63 61 6c 69 62 72 61 74 | 69 6f 6e 2e 0a 0a 0a 5c |calibrat|ion....\|
|00005700| 73 65 63 74 69 6f 6e 7b | 43 61 6c 69 62 72 61 74 |section{|Calibrat|
|00005710| 69 6f 6e 7d 0a 0a 54 68 | 65 20 70 72 6f 66 69 6c |ion}..Th|e profil|
|00005720| 65 72 20 63 6c 61 73 73 | 20 68 61 73 20 61 20 68 |er class| has a h|
|00005730| 61 72 64 20 63 6f 64 65 | 64 20 63 6f 6e 73 74 61 |ard code|d consta|
|00005740| 6e 74 20 74 68 61 74 20 | 69 73 20 61 64 64 65 64 |nt that |is added|
|00005750| 20 74 6f 20 65 61 63 68 | 0a 65 76 65 6e 74 20 68 | to each|.event h|
|00005760| 61 6e 64 6c 69 6e 67 20 | 74 69 6d 65 20 74 6f 20 |andling |time to |
|00005770| 63 6f 6d 70 65 6e 73 61 | 74 65 20 66 6f 72 20 74 |compensa|te for t|
|00005780| 68 65 20 6f 76 65 72 68 | 65 61 64 20 6f 66 20 63 |he overh|ead of c|
|00005790| 61 6c 6c 69 6e 67 20 74 | 68 65 20 74 69 6d 65 0a |alling t|he time.|
|000057a0| 66 75 6e 63 74 69 6f 6e | 2c 20 61 6e 64 20 73 6f |function|, and so|
|000057b0| 63 6b 69 6e 67 20 61 77 | 61 79 20 74 68 65 20 72 |cking aw|ay the r|
|000057c0| 65 73 75 6c 74 73 2e 20 | 20 54 68 65 20 66 6f 6c |esults. | The fol|
|000057d0| 6c 6f 77 69 6e 67 20 70 | 72 6f 63 65 64 75 72 65 |lowing p|rocedure|
|000057e0| 20 63 61 6e 0a 62 65 20 | 75 73 65 64 20 74 6f 20 | can.be |used to |
|000057f0| 6f 62 74 61 69 6e 20 74 | 68 69 73 20 63 6f 6e 73 |obtain t|his cons|
|00005800| 74 61 6e 74 20 66 6f 72 | 20 61 20 67 69 76 65 6e |tant for| a given|
|00005810| 20 70 6c 61 74 66 6f 72 | 6d 20 28 73 65 65 20 64 | platfor|m (see d|
|00005820| 69 73 63 75 73 73 69 6f | 6e 0a 69 6e 20 73 65 63 |iscussio|n.in sec|
|00005830| 74 69 6f 6e 20 4c 69 6d | 69 74 61 74 69 6f 6e 73 |tion Lim|itations|
|00005840| 20 61 62 6f 76 65 29 2e | 0a 0a 5c 62 65 67 69 6e | above).|..\begin|
|00005850| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 20 20 20 20 69 |{verbati|m}. i|
|00005860| 6d 70 6f 72 74 20 70 72 | 6f 66 69 6c 65 0a 20 20 |mport pr|ofile. |
|00005870| 20 20 70 72 20 3d 20 70 | 72 6f 66 69 6c 65 2e 50 | pr = p|rofile.P|
|00005880| 72 6f 66 69 6c 65 28 29 | 0a 20 20 20 20 70 72 2e |rofile()|. pr.|
|00005890| 63 61 6c 69 62 72 61 74 | 65 28 31 30 30 29 0a 20 |calibrat|e(100). |
|000058a0| 20 20 20 70 72 2e 63 61 | 6c 69 62 72 61 74 65 28 | pr.ca|librate(|
|000058b0| 31 30 30 29 0a 20 20 20 | 20 70 72 2e 63 61 6c 69 |100). | pr.cali|
|000058c0| 62 72 61 74 65 28 31 30 | 30 29 0a 5c 65 6e 64 7b |brate(10|0).\end{|
|000058d0| 76 65 72 62 61 74 69 6d | 7d 0a 0a 54 68 65 20 61 |verbatim|}..The a|
|000058e0| 72 67 75 6d 65 6e 74 20 | 74 6f 20 63 61 6c 69 62 |rgument |to calib|
|000058f0| 72 61 74 65 28 29 20 69 | 73 20 74 68 65 20 6e 75 |rate() i|s the nu|
|00005900| 6d 62 65 72 20 6f 66 20 | 74 69 6d 65 73 20 74 6f |mber of |times to|
|00005910| 20 74 72 79 20 74 6f 20 | 64 6f 20 74 68 65 0a 73 | try to |do the.s|
|00005920| 61 6d 70 6c 65 20 63 61 | 6c 6c 73 20 74 6f 20 67 |ample ca|lls to g|
|00005930| 65 74 20 74 68 65 20 43 | 50 55 20 74 69 6d 65 73 |et the C|PU times|
|00005940| 2e 20 20 49 66 20 79 6f | 75 72 20 63 6f 6d 70 75 |. If yo|ur compu|
|00005950| 74 65 72 20 69 73 20 5c | 65 6d 70 68 7b 76 65 72 |ter is \|emph{ver|
|00005960| 79 7d 0a 66 61 73 74 2c | 20 79 6f 75 20 6d 69 67 |y}.fast,| you mig|
|00005970| 68 74 20 68 61 76 65 20 | 74 6f 20 64 6f 3a 0a 0a |ht have |to do:..|
|00005980| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00005990| 0a 20 20 20 20 70 72 2e | 63 61 6c 69 62 72 61 74 |. pr.|calibrat|
|000059a0| 65 28 31 30 30 30 29 0a | 5c 65 6e 64 7b 76 65 72 |e(1000).|\end{ver|
|000059b0| 62 61 74 69 6d 7d 0a 0a | 6f 72 20 65 76 65 6e 3a |batim}..|or even:|
|000059c0| 0a 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |..\begin|{verbati|
|000059d0| 6d 7d 0a 20 20 20 20 70 | 72 2e 63 61 6c 69 62 72 |m}. p|r.calibr|
|000059e0| 61 74 65 28 31 30 30 30 | 30 29 0a 5c 65 6e 64 7b |ate(1000|0).\end{|
|000059f0| 76 65 72 62 61 74 69 6d | 7d 0a 0a 54 68 65 20 6f |verbatim|}..The o|
|00005a00| 62 6a 65 63 74 20 6f 66 | 20 74 68 69 73 20 65 78 |bject of| this ex|
|00005a10| 65 72 63 69 73 65 20 69 | 73 20 74 6f 20 67 65 74 |ercise i|s to get|
|00005a20| 20 61 20 66 61 69 72 6c | 79 20 63 6f 6e 73 69 73 | a fairl|y consis|
|00005a30| 74 65 6e 74 20 72 65 73 | 75 6c 74 2e 0a 57 68 65 |tent res|ult..Whe|
|00005a40| 6e 20 79 6f 75 20 68 61 | 76 65 20 61 20 63 6f 6e |n you ha|ve a con|
|00005a50| 73 69 73 74 65 6e 74 20 | 61 6e 73 77 65 72 2c 20 |sistent |answer, |
|00005a60| 79 6f 75 20 61 72 65 20 | 72 65 61 64 79 20 74 6f |you are |ready to|
|00005a70| 20 75 73 65 20 74 68 61 | 74 20 6e 75 6d 62 65 72 | use tha|t number|
|00005a80| 20 69 6e 0a 74 68 65 20 | 73 6f 75 72 63 65 20 63 | in.the |source c|
|00005a90| 6f 64 65 2e 20 20 46 6f | 72 20 61 20 53 75 6e 20 |ode. Fo|r a Sun |
|00005aa0| 53 70 61 72 63 73 74 61 | 74 69 6f 6e 20 31 30 30 |Sparcsta|tion 100|
|00005ab0| 30 20 72 75 6e 6e 69 6e | 67 20 53 6f 6c 61 72 69 |0 runnin|g Solari|
|00005ac0| 73 20 32 2e 33 2c 20 74 | 68 65 0a 6d 61 67 69 63 |s 2.3, t|he.magic|
|00005ad0| 61 6c 20 6e 75 6d 62 65 | 72 20 69 73 20 61 62 6f |al numbe|r is abo|
|00005ae0| 75 74 20 2e 30 30 30 35 | 33 2e 20 20 49 66 20 79 |ut .0005|3. If y|
|00005af0| 6f 75 20 68 61 76 65 20 | 61 20 63 68 6f 69 63 65 |ou have |a choice|
|00005b00| 2c 20 79 6f 75 20 61 72 | 65 20 62 65 74 74 65 72 |, you ar|e better|
|00005b10| 0a 6f 66 66 20 77 69 74 | 68 20 61 20 73 6d 61 6c |.off wit|h a smal|
|00005b20| 6c 65 72 20 63 6f 6e 73 | 74 61 6e 74 2c 20 61 6e |ler cons|tant, an|
|00005b30| 64 20 79 6f 75 72 20 72 | 65 73 75 6c 74 73 20 77 |d your r|esults w|
|00005b40| 69 6c 6c 20 60 60 6c 65 | 73 73 20 6f 66 74 65 6e |ill ``le|ss often|
|00005b50| 27 27 20 73 68 6f 77 0a | 75 70 20 61 73 20 6e 65 |'' show.|up as ne|
|00005b60| 67 61 74 69 76 65 20 69 | 6e 20 70 72 6f 66 69 6c |gative i|n profil|
|00005b70| 65 20 73 74 61 74 69 73 | 74 69 63 73 2e 0a 0a 54 |e statis|tics...T|
|00005b80| 68 65 20 66 6f 6c 6c 6f | 77 69 6e 67 20 73 68 6f |he follo|wing sho|
|00005b90| 77 73 20 68 6f 77 20 74 | 68 65 20 74 72 61 63 65 |ws how t|he trace|
|00005ba0| 5f 64 69 73 70 61 74 63 | 68 28 29 20 6d 65 74 68 |_dispatc|h() meth|
|00005bb0| 6f 64 20 69 6e 20 74 68 | 65 20 50 72 6f 66 69 6c |od in th|e Profil|
|00005bc0| 65 0a 63 6c 61 73 73 20 | 73 68 6f 75 6c 64 20 62 |e.class |should b|
|00005bd0| 65 20 6d 6f 64 69 66 69 | 65 64 20 74 6f 20 69 6e |e modifi|ed to in|
|00005be0| 73 74 61 6c 6c 20 74 68 | 65 20 63 61 6c 69 62 72 |stall th|e calibr|
|00005bf0| 61 74 69 6f 6e 20 63 6f | 6e 73 74 61 6e 74 20 6f |ation co|nstant o|
|00005c00| 6e 20 61 20 53 75 6e 0a | 53 70 61 72 63 73 74 61 |n a Sun.|Sparcsta|
|00005c10| 74 69 6f 6e 20 31 30 30 | 30 3a 0a 0a 5c 62 65 67 |tion 100|0:..\beg|
|00005c20| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 20 20 20 |in{verba|tim}. |
|00005c30| 20 64 65 66 20 74 72 61 | 63 65 5f 64 69 73 70 61 | def tra|ce_dispa|
|00005c40| 74 63 68 28 73 65 6c 66 | 2c 20 66 72 61 6d 65 2c |tch(self|, frame,|
|00005c50| 20 65 76 65 6e 74 2c 20 | 61 72 67 29 3a 0a 20 20 | event, |arg):. |
|00005c60| 20 20 20 20 20 20 74 20 | 3d 20 73 65 6c 66 2e 74 | t |= self.t|
|00005c70| 69 6d 65 72 28 29 0a 20 | 20 20 20 20 20 20 20 74 |imer(). | t|
|00005c80| 20 3d 20 74 5b 30 5d 20 | 2b 20 74 5b 31 5d 20 2d | = t[0] |+ t[1] -|
|00005c90| 20 73 65 6c 66 2e 74 20 | 2d 20 2e 30 30 30 35 33 | self.t |- .00053|
|00005ca0| 20 23 20 43 61 6c 69 62 | 72 61 74 69 6f 6e 20 63 | # Calib|ration c|
|00005cb0| 6f 6e 73 74 61 6e 74 0a | 0a 20 20 20 20 20 20 20 |onstant.|. |
|00005cc0| 20 69 66 20 73 65 6c 66 | 2e 64 69 73 70 61 74 63 | if self|.dispatc|
|00005cd0| 68 5b 65 76 65 6e 74 5d | 28 66 72 61 6d 65 2c 74 |h[event]|(frame,t|
|00005ce0| 29 3a 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 74 |):. | t|
|00005cf0| 20 3d 20 73 65 6c 66 2e | 74 69 6d 65 72 28 29 0a | = self.|timer().|
|00005d00| 20 20 20 20 20 20 20 20 | 20 20 20 20 73 65 6c 66 | | self|
|00005d10| 2e 74 20 3d 20 74 5b 30 | 5d 20 2b 20 74 5b 31 5d |.t = t[0|] + t[1]|
|00005d20| 0a 20 20 20 20 20 20 20 | 20 65 6c 73 65 3a 0a 20 |. | else:. |
|00005d30| 20 20 20 20 20 20 20 20 | 20 20 20 72 20 3d 20 73 | | r = s|
|00005d40| 65 6c 66 2e 74 69 6d 65 | 72 28 29 0a 20 20 20 20 |elf.time|r(). |
|00005d50| 20 20 20 20 20 20 20 20 | 73 65 6c 66 2e 74 20 3d | |self.t =|
|00005d60| 20 72 5b 30 5d 20 2b 20 | 72 5b 31 5d 20 2d 20 74 | r[0] + |r[1] - t|
|00005d70| 20 23 20 70 75 74 20 62 | 61 63 6b 20 75 6e 72 65 | # put b|ack unre|
|00005d80| 63 6f 72 64 65 64 20 64 | 65 6c 74 61 0a 20 20 20 |corded d|elta. |
|00005d90| 20 20 20 20 20 72 65 74 | 75 72 6e 0a 5c 65 6e 64 | ret|urn.\end|
|00005da0| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 0a 4e 6f 74 65 |{verbati|m}..Note|
|00005db0| 20 74 68 61 74 20 69 66 | 20 74 68 65 72 65 20 69 | that if| there i|
|00005dc0| 73 20 6e 6f 20 63 61 6c | 69 62 72 61 74 69 6f 6e |s no cal|ibration|
|00005dd0| 20 63 6f 6e 73 74 61 6e | 74 2c 20 74 68 65 6e 20 | constan|t, then |
|00005de0| 74 68 65 20 6c 69 6e 65 | 0a 63 6f 6e 74 61 69 6e |the line|.contain|
|00005df0| 69 6e 67 20 74 68 65 20 | 63 61 6c 6c 69 62 72 61 |ing the |callibra|
|00005e00| 74 69 6f 6e 20 63 6f 6e | 73 74 61 6e 74 20 73 68 |tion con|stant sh|
|00005e10| 6f 75 6c 64 20 73 69 6d | 70 6c 79 20 73 61 79 3a |ould sim|ply say:|
|00005e20| 0a 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |..\begin|{verbati|
|00005e30| 6d 7d 0a 20 20 20 20 20 | 20 20 20 74 20 3d 20 74 |m}. | t = t|
|00005e40| 5b 30 5d 20 2b 20 74 5b | 31 5d 20 2d 20 73 65 6c |[0] + t[|1] - sel|
|00005e50| 66 2e 74 20 20 23 20 6e | 6f 20 63 61 6c 69 62 72 |f.t # n|o calibr|
|00005e60| 61 74 69 6f 6e 20 63 6f | 6e 73 74 61 6e 74 0a 5c |ation co|nstant.\|
|00005e70| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 0a 59 |end{verb|atim}..Y|
|00005e80| 6f 75 20 63 61 6e 20 61 | 6c 73 6f 20 61 63 68 69 |ou can a|lso achi|
|00005e90| 65 76 65 20 74 68 65 20 | 73 61 6d 65 20 72 65 73 |eve the |same res|
|00005ea0| 75 6c 74 73 20 75 73 69 | 6e 67 20 61 20 64 65 72 |ults usi|ng a der|
|00005eb0| 69 76 65 64 20 63 6c 61 | 73 73 20 28 61 6e 64 20 |ived cla|ss (and |
|00005ec0| 74 68 65 0a 70 72 6f 66 | 69 6c 65 72 20 77 69 6c |the.prof|iler wil|
|00005ed0| 6c 20 61 63 74 75 61 6c | 6c 79 20 72 75 6e 20 65 |l actual|ly run e|
|00005ee0| 71 75 61 6c 6c 79 20 66 | 61 73 74 21 21 29 2c 20 |qually f|ast!!), |
|00005ef0| 62 75 74 20 74 68 65 20 | 61 62 6f 76 65 20 6d 65 |but the |above me|
|00005f00| 74 68 6f 64 20 69 73 0a | 74 68 65 20 73 69 6d 70 |thod is.|the simp|
|00005f10| 6c 65 73 74 20 74 6f 20 | 75 73 65 2e 20 20 49 20 |lest to |use. I |
|00005f20| 63 6f 75 6c 64 20 68 61 | 76 65 20 6d 61 64 65 20 |could ha|ve made |
|00005f30| 74 68 65 20 70 72 6f 66 | 69 6c 65 72 20 60 60 73 |the prof|iler ``s|
|00005f40| 65 6c 66 0a 63 61 6c 69 | 62 72 61 74 69 6e 67 27 |elf.cali|brating'|
|00005f50| 27 2c 20 62 75 74 20 69 | 74 20 77 6f 75 6c 64 20 |', but i|t would |
|00005f60| 68 61 76 65 20 6d 61 64 | 65 20 74 68 65 20 69 6e |have mad|e the in|
|00005f70| 69 74 69 61 6c 69 7a 61 | 74 69 6f 6e 20 6f 66 20 |itializa|tion of |
|00005f80| 74 68 65 0a 70 72 6f 66 | 69 6c 65 72 20 63 6c 61 |the.prof|iler cla|
|00005f90| 73 73 20 73 6c 6f 77 65 | 72 2c 20 61 6e 64 20 77 |ss slowe|r, and w|
|00005fa0| 6f 75 6c 64 20 68 61 76 | 65 20 72 65 71 75 69 72 |ould hav|e requir|
|00005fb0| 65 64 20 73 6f 6d 65 20 | 5c 65 6d 70 68 7b 76 65 |ed some |\emph{ve|
|00005fc0| 72 79 7d 20 66 61 6e 63 | 79 0a 63 6f 64 69 6e 67 |ry} fanc|y.coding|
|00005fd0| 2c 20 6f 72 20 65 6c 73 | 65 20 74 68 65 20 75 73 |, or els|e the us|
|00005fe0| 65 20 6f 66 20 61 20 76 | 61 72 69 61 62 6c 65 20 |e of a v|ariable |
|00005ff0| 77 68 65 72 65 20 74 68 | 65 20 63 6f 6e 73 74 61 |where th|e consta|
|00006000| 6e 74 20 5c 73 61 6d 70 | 7b 2e 30 30 30 35 33 7d |nt \samp|{.00053}|
|00006010| 0a 77 61 73 20 70 6c 61 | 63 65 64 20 69 6e 20 74 |.was pla|ced in t|
|00006020| 68 65 20 63 6f 64 65 20 | 73 68 6f 77 6e 2e 20 20 |he code |shown. |
|00006030| 54 68 69 73 20 69 73 20 | 61 20 5c 73 74 72 6f 6e |This is |a \stron|
|00006040| 67 7b 56 45 52 59 7d 20 | 63 72 69 74 69 63 61 6c |g{VERY} |critical|
|00006050| 0a 70 65 72 66 6f 72 6d | 61 6e 63 65 20 73 65 63 |.perform|ance sec|
|00006060| 74 69 6f 6e 2c 20 61 6e | 64 20 74 68 65 72 65 20 |tion, an|d there |
|00006070| 69 73 20 6e 6f 20 72 65 | 61 73 6f 6e 20 74 6f 20 |is no re|ason to |
|00006080| 75 73 65 20 61 20 76 61 | 72 69 61 62 6c 65 20 6c |use a va|riable l|
|00006090| 6f 6f 6b 75 70 0a 61 74 | 20 74 68 69 73 20 70 6f |ookup.at| this po|
|000060a0| 69 6e 74 2c 20 77 68 65 | 6e 20 61 20 63 6f 6e 73 |int, whe|n a cons|
|000060b0| 74 61 6e 74 20 63 61 6e | 20 62 65 20 75 73 65 64 |tant can| be used|
|000060c0| 2e 0a 0a 0a 5c 73 65 63 | 74 69 6f 6e 7b 45 78 74 |....\sec|tion{Ext|
|000060d0| 65 6e 73 69 6f 6e 73 20 | 2d 2d 2d 20 44 65 72 69 |ensions |--- Deri|
|000060e0| 76 69 6e 67 20 42 65 74 | 74 65 72 20 50 72 6f 66 |ving Bet|ter Prof|
|000060f0| 69 6c 65 72 73 7d 0a 5c | 6e 6f 64 65 6e 61 6d 65 |ilers}.\|nodename|
|00006100| 7b 50 72 6f 66 69 6c 65 | 72 20 45 78 74 65 6e 73 |{Profile|r Extens|
|00006110| 69 6f 6e 73 7d 0a 0a 54 | 68 65 20 5c 63 6f 64 65 |ions}..T|he \code|
|00006120| 7b 50 72 6f 66 69 6c 65 | 7d 20 63 6c 61 73 73 20 |{Profile|} class |
|00006130| 6f 66 20 6d 6f 64 75 6c | 65 20 5c 63 6f 64 65 7b |of modul|e \code{|
|00006140| 70 72 6f 66 69 6c 65 7d | 20 77 61 73 20 77 72 69 |profile}| was wri|
|00006150| 74 74 65 6e 20 73 6f 20 | 74 68 61 74 0a 64 65 72 |tten so |that.der|
|00006160| 69 76 65 64 20 63 6c 61 | 73 73 65 73 20 63 6f 75 |ived cla|sses cou|
|00006170| 6c 64 20 62 65 20 64 65 | 76 65 6c 6f 70 65 64 20 |ld be de|veloped |
|00006180| 74 6f 20 65 78 74 65 6e | 64 20 74 68 65 20 70 72 |to exten|d the pr|
|00006190| 6f 66 69 6c 65 72 2e 20 | 20 52 61 74 68 65 72 0a |ofiler. | Rather.|
|000061a0| 74 68 61 6e 20 64 65 73 | 63 72 69 62 69 6e 67 20 |than des|cribing |
|000061b0| 61 6c 6c 20 74 68 65 20 | 64 65 74 61 69 6c 73 20 |all the |details |
|000061c0| 6f 66 20 73 75 63 68 20 | 61 6e 20 65 66 66 6f 72 |of such |an effor|
|000061d0| 74 2c 20 49 27 6c 6c 20 | 6a 75 73 74 20 70 72 65 |t, I'll |just pre|
|000061e0| 73 65 6e 74 0a 74 68 65 | 20 66 6f 6c 6c 6f 77 69 |sent.the| followi|
|000061f0| 6e 67 20 74 77 6f 20 65 | 78 61 6d 70 6c 65 73 20 |ng two e|xamples |
|00006200| 6f 66 20 64 65 72 69 76 | 65 64 20 63 6c 61 73 73 |of deriv|ed class|
|00006210| 65 73 20 74 68 61 74 20 | 63 61 6e 20 62 65 20 75 |es that |can be u|
|00006220| 73 65 64 20 74 6f 20 64 | 6f 0a 70 72 6f 66 69 6c |sed to d|o.profil|
|00006230| 69 6e 67 2e 20 20 49 66 | 20 74 68 65 20 72 65 61 |ing. If| the rea|
|00006240| 64 65 72 20 69 73 20 61 | 6e 20 61 76 69 64 20 50 |der is a|n avid P|
|00006250| 79 74 68 6f 6e 20 70 72 | 6f 67 72 61 6d 6d 65 72 |ython pr|ogrammer|
|00006260| 2c 20 74 68 65 6e 20 69 | 74 20 73 68 6f 75 6c 64 |, then i|t should|
|00006270| 0a 62 65 20 70 6f 73 73 | 69 62 6c 65 20 74 6f 20 |.be poss|ible to |
|00006280| 75 73 65 20 74 68 65 73 | 65 20 61 73 20 61 20 6d |use thes|e as a m|
|00006290| 6f 64 65 6c 20 61 6e 64 | 20 63 72 65 61 74 65 20 |odel and| create |
|000062a0| 73 69 6d 69 6c 61 72 20 | 28 61 6e 64 20 70 65 72 |similar |(and per|
|000062b0| 63 68 61 6e 63 65 0a 62 | 65 74 74 65 72 29 20 70 |chance.b|etter) p|
|000062c0| 72 6f 66 69 6c 65 20 63 | 6c 61 73 73 65 73 2e 0a |rofile c|lasses..|
|000062d0| 0a 49 66 20 61 6c 6c 20 | 79 6f 75 20 77 61 6e 74 |.If all |you want|
|000062e0| 20 74 6f 20 64 6f 20 69 | 73 20 63 68 61 6e 67 65 | to do i|s change|
|000062f0| 20 68 6f 77 20 74 68 65 | 20 74 69 6d 65 72 20 69 | how the| timer i|
|00006300| 73 20 63 61 6c 6c 65 64 | 2c 20 6f 72 20 77 68 69 |s called|, or whi|
|00006310| 63 68 0a 74 69 6d 65 72 | 20 66 75 6e 63 74 69 6f |ch.timer| functio|
|00006320| 6e 20 69 73 20 75 73 65 | 64 2c 20 74 68 65 6e 20 |n is use|d, then |
|00006330| 74 68 65 20 62 61 73 69 | 63 20 63 6c 61 73 73 20 |the basi|c class |
|00006340| 68 61 73 20 61 6e 20 6f | 70 74 69 6f 6e 20 66 6f |has an o|ption fo|
|00006350| 72 20 74 68 61 74 20 69 | 6e 0a 74 68 65 20 63 6f |r that i|n.the co|
|00006360| 6e 73 74 72 75 63 74 6f | 72 20 66 6f 72 20 74 68 |nstructo|r for th|
|00006370| 65 20 63 6c 61 73 73 2e | 20 20 43 6f 6e 73 69 64 |e class.| Consid|
|00006380| 65 72 20 70 61 73 73 69 | 6e 67 20 74 68 65 20 6e |er passi|ng the n|
|00006390| 61 6d 65 20 6f 66 20 61 | 0a 66 75 6e 63 74 69 6f |ame of a|.functio|
|000063a0| 6e 20 74 6f 20 63 61 6c | 6c 20 69 6e 74 6f 20 74 |n to cal|l into t|
|000063b0| 68 65 20 63 6f 6e 73 74 | 72 75 63 74 6f 72 3a 0a |he const|ructor:.|
|000063c0| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|000063d0| 7d 0a 20 20 20 20 70 72 | 20 3d 20 70 72 6f 66 69 |}. pr| = profi|
|000063e0| 6c 65 2e 50 72 6f 66 69 | 6c 65 28 79 6f 75 72 5f |le.Profi|le(your_|
|000063f0| 74 69 6d 65 5f 66 75 6e | 63 29 0a 5c 65 6e 64 7b |time_fun|c).\end{|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.