Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcd845a

Browse files
committed
Lots of small markup adjustments.
1 parent 61a0a73 commit fcd845a

2 files changed

Lines changed: 118 additions & 113 deletions

File tree

Doc/lib/libhotshot.tex

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ \section{\module{hotshot} ---
22
High performance logging profiler}
33

44
\declaremodule{standard}{hotshot}
5+
\modulesynopsis{High performance logging profiler, mostly written in C.}
56
\moduleauthor{Fred L. Drake, Jr.}{[email protected]}
67
\sectionauthor{Anthony Baxter}{[email protected]}
78

8-
99
\versionadded{2.2}
1010

11-
\modulesynopsis{High performance logging profiler, mostly written in C.}
1211

13-
14-
This module provides a nicer interface to the \code{_hotshot} C module.
12+
This module provides a nicer interface to the \module{_hotshot} C module.
1513
Hotshot is a replacement for the existing \refmodule{profile} module. As it's
16-
written mostly in C, it should result in a much smaller performance impact
17-
than the existing profile module.
18-
19-
\begin{classdesc}{Profile}{logfile, \optional{, lineevents=0, linetimings=1}}
20-
21-
The profiler object. The argument \var{logfile} is the name of a log file
22-
to use for logged profile data. The argument \var{lineevents} specifies whether
23-
to generate events for every source line, or just on function call/return. It
24-
defaults to 0 (only log function call/return). The argument \var{linetimings}
25-
specifies whether to record timing information. It defaults to 1 (store timing
14+
written mostly in C, it should result in a much smaller performance impact
15+
than the existing \refmodule{profile} module.
16+
17+
\begin{classdesc}{Profile}{logfile\optional{,
18+
lineevents\code{=0}\optional{,
19+
linetimings\code{=1}}}}
20+
The profiler object. The argument \var{logfile} is the name of a log
21+
file to use for logged profile data. The argument \var{lineevents}
22+
specifies whether to generate events for every source line, or just on
23+
function call/return. It defaults to \code{0} (only log function
24+
call/return). The argument \var{linetimings} specifies whether to
25+
record timing information. It defaults to \code{1} (store timing
2626
information).
27-
2827
\end{classdesc}
2928

29+
3030
\subsection{Profile Objects \label{hotshot-objects}}
3131

3232
Profile objects have the following methods:
@@ -38,22 +38,19 @@ \subsection{Profile Objects \label{hotshot-objects}}
3838
\begin{methoddesc}{close}{}
3939
Close the logfile and terminate the profiler.
4040
\end{methoddesc}
41-
42-
%
41+
4342
\begin{methoddesc}{fileno}{}
4443
Return the file descriptor of the profiler's log file.
4544
\end{methoddesc}
4645

4746
\begin{methoddesc}{run}{cmd}
48-
Profile an exec-compatible string in the script environment.
49-
50-
The globals from the \module{__main__} module are used as
47+
Profile an \keyword{exec}-compatible string in the script environment.
48+
The globals from the \refmodule[main]{__main__} module are used as
5149
both the globals and locals for the script.
5250
\end{methoddesc}
5351

5452
\begin{methoddesc}{runcall}{func, *args, **keywords}
5553
Profile a single call of a callable.
56-
5754
Additional positional and keyword arguments may be passed
5855
along; the result of the call is returned, and exceptions are
5956
allowed to propogate cleanly, while ensuring that profiling is
@@ -62,8 +59,7 @@ \subsection{Profile Objects \label{hotshot-objects}}
6259

6360

6461
\begin{methoddesc}{runctx}{cmd, globals, locals}
65-
Evaluate an exec-compatible string in a specific environment.
66-
62+
Evaluate an \keyword{exec}-compatible string in a specific environment.
6763
The string is compiled before profiling begins.
6864
\end{methoddesc}
6965

@@ -75,32 +71,33 @@ \subsection{Profile Objects \label{hotshot-objects}}
7571
Stop the profiler.
7672
\end{methoddesc}
7773

74+
7875
\subsection{Using hotshot data}
79-
\declaremodule{standard}{hotshot.stats}
8076

77+
\declaremodule{standard}{hotshot.stats}
8178
\modulesynopsis{Statistical analysis for Hotshot}
8279

8380
\versionadded{2.2}
8481

85-
This module loads hotshot profiling data into the standard \module{pstats}
82+
This module loads hotshot profiling data into the standard \module{pstats}
8683
Stats objects.
8784

8885
\begin{funcdesc}{load}{filename}
89-
Load hotshot data from \var{filename}. Returns an instance
86+
Load hotshot data from \var{filename}. Returns an instance
9087
of the \class{pstats.Stats} class.
9188
\end{funcdesc}
9289

9390
\begin{seealso}
94-
\seemodule{profile}{The profile module's \class{Stats} class }
91+
\seemodule{profile}{The \module{profile} module's \class{Stats} class}
9592
\end{seealso}
9693

94+
9795
\subsection{Example Usage \label{hotshot-example}}
9896

99-
Note that this example runs the python "benchmark" pystones. It can
97+
Note that this example runs the python ``benchmark'' pystones. It can
10098
take some time to run, and will produce large output files.
10199

102100
\begin{verbatim}
103-
104101
>>> import hotshot, hotshot.stats, test.pystone
105102
>>> prof = hotshot.Profile("stones.prof")
106103
>>> benchtime, stones = prof.runcall(test.pystone.pystones)
@@ -120,7 +117,4 @@ \subsection{Example Usage \label{hotshot-example}}
120117
.
121118
.
122119
.
123-
124120
\end{verbatim}
125-
126-

Doc/lib/libtimeit.tex

Lines changed: 92 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ \section{\module{timeit} ---
44
\declaremodule{standard}{timeit}
55
\modulesynopsis{Measure the execution time of small code snippets.}
66

7+
\versionadded{2.3}
78
\index{Benchmarking}
89
\index{Performance}
910

10-
\versionadded{2.3}
11-
12-
This module provides a simple way to time small bits of Python code. It has
13-
both command line as well as callable interfaces. It avoids a number of
14-
common traps for measuring execution times. See also Tim Peters'
15-
introduction to the Algorithms chapter in the ``Python Cookbook'', published
16-
by O'Reilly.
11+
This module provides a simple way to time small bits of Python code.
12+
It has both command line as well as callable interfaces. It avoids a
13+
number of common traps for measuring execution times. See also Tim
14+
Peters' introduction to the ``Algorithms'' chapter in the
15+
\citetitle{Python Cookbook}, published by O'Reilly.
1716

18-
The module interface defines the following public class:
17+
The module defines the following public class:
1918

20-
\begin{classdesc}{Timer}{\optional{stmt='pass'
21-
\optional{, setup='pass'
22-
\optional{, timer=<timer function>}}}}
19+
\begin{classdesc}{Timer}{\optional{stmt=\code{'pass'}
20+
\optional{, setup=\code{'pass'}
21+
\optional{, timer=<timer function>}}}}
2322
Class for timing execution speed of small code snippets.
2423

25-
The constructor takes a statement to be timed, an additional statement used
26-
for setup, and a timer function. Both statements default to 'pass'; the
27-
timer function is platform-dependent (see the module doc string).
24+
The constructor takes a statement to be timed, an additional statement
25+
used for setup, and a timer function. Both statements default to
26+
\code{'pass'}; the timer function is platform-dependent (see the
27+
module doc string). The statements may contain newlines, as long as
28+
they don't contain multi-line string literals.
2829

29-
To measure the execution time of the first statement, use the timeit()
30-
method. The repeat() method is a convenience to call timeit() multiple
31-
times and return a list of results.
32-
33-
The statements may contain newlines, as long as they don't contain
34-
multi-line string literals.
30+
To measure the execution time of the first statement, use the
31+
\method{timeit()} method. The \method{repeat()} method is a
32+
convenience to call \method{timeit()} multiple times and return a list
33+
of results.
34+
\end{classdesc}
3535

36-
\begin{methoddesc}{print_exc}{\optional{file=None}}
36+
\begin{methoddesc}{print_exc}{\optional{file=\constant{None}}}
3737
Helper to print a traceback from the timed code.
3838

3939
Typical use:
@@ -48,20 +48,21 @@ \section{\module{timeit} ---
4848

4949
The advantage over the standard traceback is that source lines in the
5050
compiled template will be displayed.
51-
52-
The optional file argument directs where the traceback is sent; it defaults
53-
to \code{sys.stderr}.
51+
The optional \var{file} argument directs where the traceback is sent;
52+
it defaults to \code{sys.stderr}.
5453
\end{methoddesc}
5554

56-
\begin{methoddesc}{repeat}{\optional{repeat=3\optional{, number=1000000}}}
55+
\begin{methoddesc}{repeat}{\optional{repeat\code{=3}\optional{,
56+
number\code{=1000000}}}}
5757
Call \method{timeit()} a few times.
5858

59-
This is a convenience function that calls the \method{timeit()} repeatedly,
60-
returning a list of results. The first argument specifies how many times to
61-
call \function{timeit()}. The second argument specifies the \code{number}
62-
argument for \function{timeit()}.
59+
This is a convenience function that calls the \method{timeit()}
60+
repeatedly, returning a list of results. The first argument specifies
61+
how many times to call \method{timeit()}. The second argument
62+
specifies the \var{number} argument for \function{timeit()}.
6363

64-
Note: it's tempting to calculate mean and standard deviation from the result
64+
\begin{notice}
65+
It's tempting to calculate mean and standard deviation from the result
6566
vector and report these. However, this is not very useful. In a typical
6667
case, the lowest value gives a lower bound for how fast your machine can run
6768
the given code snippet; higher values in the result vector are typically not
@@ -70,25 +71,26 @@ \section{\module{timeit} ---
7071
probably the only number you should be interested in. After that, you
7172
should look at the entire vector and apply common sense rather than
7273
statistics.
74+
\end{notice}
7375
\end{methoddesc}
7476

75-
\begin{methoddesc}{timeit}{\optional{number=1000000}}
76-
Time \code{number} executions of the main statement.
77-
78-
To be precise, this executes the setup statement once, and then returns the
79-
time it takes to execute the main statement a number of times, as a float
80-
measured in seconds. The argument is the number of times through the loop,
81-
defaulting to one million. The main statement, the setup statement and the
82-
timer function to be used are passed to the constructor.
77+
\begin{methoddesc}{timeit}{\optional{number\code{=1000000}}}
78+
Time \var{number} executions of the main statement.
79+
This executes the setup statement once, and then
80+
returns the time it takes to execute the main statement a number of
81+
times, measured in seconds as a float. The argument is the number of
82+
times through the loop, defaulting to one million. The main
83+
statement, the setup statement and the timer function to be used are
84+
passed to the constructor.
8385
\end{methoddesc}
84-
\end{classdesc}
86+
8587

8688
\subsection{Command Line Interface}
8789

8890
When called as a program from the command line, the following form is used:
8991

9092
\begin{verbatim}
91-
python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
93+
python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
9294
\end{verbatim}
9395

9496
where the following options are understood:
@@ -97,65 +99,74 @@ \subsection{Command Line Interface}
9799
\item[-n N/--number=N] how many times to execute 'statement'
98100
\item[-r N/--repeat=N] how many times to repeat the timer (default 3)
99101
\item[-s S/--setup=S] statement to be executed once initially (default
100-
'pass')
101-
\item[-t/--time] use time.time() (default on all platforms but Windows)
102-
\item[-c/--clock] use time.clock() (default on Windows)
102+
\code{'pass'})
103+
\item[-t/--time] use \function{time.time()}
104+
(default on all platforms but Windows)
105+
\item[-c/--clock] use \function{time.clock()} (default on Windows)
103106
\item[-v/--verbose] print raw timing results; repeat for more digits
104-
precision
107+
precision
105108
\item[-h/--help] print a short usage message and exit
106109
\end{description}
107110

108-
A multi-line statement may be given by specifying each line as a separate
109-
statement argument; indented lines are possible by enclosing an argument in
110-
quotes and using leading spaces. Multiple -s options are treated similarly.
111-
112-
If -n is not given, a suitable number of loops is calculated by trying
113-
successive powers of 10 until the total time is at least 0.2 seconds.
114-
115-
The default timer function is platform dependent. On Windows, clock() has
116-
microsecond granularity but time()'s granularity is 1/60th of a second; on
117-
Unix, clock() has 1/100th of a second granularity and time() is much more
118-
precise. On either platform, the default timer functions measures wall
119-
clock time, not the CPU time. This means that other processes running on
120-
the same computer may interfere with the timing. The best thing to do when
121-
accurate timing is necessary is to repeat the timing a few times and use the
122-
best time. The -r option is good for this; the default of 3 repetitions is
123-
probably enough in most cases. On Unix, you can use clock() to measure CPU
124-
time.
125-
126-
Note: there is a certain baseline overhead associated with executing a pass
127-
statement. The code here doesn't try to hide it, but you should be aware of
128-
it. The baseline overhead can be measured by invoking the program without
129-
arguments.
130-
131-
The baseline overhead differs between Python versions! Also, to fairly
132-
compare older Python versions to Python 2.3, you may want to use python -O
133-
for the older versions to avoid timing SET_LINENO instructions.
111+
A multi-line statement may be given by specifying each line as a
112+
separate statement argument; indented lines are possible by enclosing
113+
an argument in quotes and using leading spaces. Multiple
114+
\programopt{-s} options are treated similarly.
115+
116+
If \programopt{-n} is not given, a suitable number of loops is
117+
calculated by trying successive powers of 10 until the total time is
118+
at least 0.2 seconds.
119+
120+
The default timer function is platform dependent. On Windows,
121+
\function{time.clock()} has microsecond granularity but
122+
\function{time.time()}'s granularity is 1/60th of a second; on \UNIX,
123+
\function{time.clock()} has 1/100th of a second granularity and
124+
\function{time.time()} is much more precise. On either platform, the
125+
default timer functions measures wall clock time, not the CPU time.
126+
This means that other processes running on the same computer may
127+
interfere with the timing. The best thing to do when accurate timing
128+
is necessary is to repeat the timing a few times and use the best
129+
time. The \programopt{-r} option is good for this; the default of 3
130+
repetitions is probably enough in most cases. On \UNIX, you can use
131+
\function{time.clock()} to measure CPU time.
132+
133+
\begin{notice}
134+
There is a certain baseline overhead associated with executing a
135+
pass statement. The code here doesn't try to hide it, but you
136+
should be aware of it. The baseline overhead can be measured by
137+
invoking the program without arguments.
138+
\end{notice}
139+
140+
The baseline overhead differs between Python versions! Also, to
141+
fairly compare older Python versions to Python 2.3, you may want to
142+
use Python's \programopt{-O} option for the older versions to avoid
143+
timing \code{SET_LINENO} instructions.
134144

135145
\subsection{Examples}
136146

137-
Here are two example sessions (one using the command line, one using the
138-
module interface) that compare the cost of using \function{hasattr()}
139-
vs. try/except to test for missing and present object attributes.
147+
Here are two example sessions (one using the command line, one using
148+
the module interface) that compare the cost of using
149+
\function{hasattr()} vs. \keyword{try}/\keyword{except} to test for
150+
missing and present object attributes.
140151

141152
\begin{verbatim}
142-
\% timeit.py 'try:' ' str.__nonzero__' 'except AttributeError:' ' pass'
153+
% timeit.py 'try:' ' str.__nonzero__' 'except AttributeError:' ' pass'
143154
100000 loops, best of 3: 15.7 usec per loop
144-
\% timeit.py 'if hasattr(str, "__nonzero__"): pass'
155+
% timeit.py 'if hasattr(str, "__nonzero__"): pass'
145156
100000 loops, best of 3: 4.26 usec per loop
146-
\% timeit.py 'try:' ' int.__nonzero__' 'except AttributeError:' ' pass'
157+
% timeit.py 'try:' ' int.__nonzero__' 'except AttributeError:' ' pass'
147158
1000000 loops, best of 3: 1.43 usec per loop
148-
\% timeit.py 'if hasattr(int, "__nonzero__"): pass'
159+
% timeit.py 'if hasattr(int, "__nonzero__"): pass'
149160
100000 loops, best of 3: 2.23 usec per loop
150161
\end{verbatim}
151162

152163
\begin{verbatim}
153164
>>> import timeit
154165
>>> s = """\
155166
... try:
156-
... str.__nonzero__
167+
... str.__nonzero__
157168
... except AttributeError:
158-
... pass
169+
... pass
159170
... """
160171
>>> t = timeit.Timer(stmt=s)
161172
>>> print "%.2f usec/pass" % (1000000 * t.timeit(number=100000)/100000)
@@ -168,9 +179,9 @@ \subsection{Examples}
168179
4.85 usec/pass
169180
>>> s = """\
170181
... try:
171-
... int.__nonzero__
182+
... int.__nonzero__
172183
... except AttributeError:
173-
... pass
184+
... pass
174185
... """
175186
>>> t = timeit.Timer(stmt=s)
176187
>>> print "%.2f usec/pass" % (1000000 * t.timeit(number=100000)/100000)

0 commit comments

Comments
 (0)