-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.txt
137 lines (92 loc) · 2.77 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Aeon
====
Measures how often designated functions, methods, or pieces of code are
executed and what their runtime is. Optionally prints a nice report to
the screen, although the raw data is available for further processing as
well.
Outline
-------
1. Mark parts of the code that should be monitored with the provided
context manager or decorators.
2. Tell your program to output the report or provide you the data when
it's done.
3. Run your program.
4. \?\?\?\?\?
5. Profit.
Basic Usage
-----------
How to designate code that should be monitored.
A free-standing piece of code.
.. code:: python
from aeon import timer
with timer('my measurement'):
# do stuff here...
# to assign the measurement to a specific group
with timer('my measurement', 'general frobnication'):
# do stuff here
A function.
.. code:: python
from aeon import timer
@timer
def my_function():
pass
A method.
.. code:: python
from aeon import timer
class Foo(object):
@timer.method
def bar(self):
pass
How to see the report.
.. code:: python
from aeon import timer
print timer.report()
print timer # equivalent
Further features
----------------
You can instantiate your own timer if you want to, in case you want to
use several in parallel.
.. code:: python
from aeon import Timer
my_timer= Timer()
with my_timer('my_measurement'):
pass
# or
with my_timer('my_measurement', 'my_group'):
pass
@my_timer
def foo():
pass
class Foo(object):
@my_timer.method
def bar(self):
pass
The timer object can be queried for specific measurements or the data
with which it generates the report.
Also, nothing prevents you from using the Measurement class on its own:
.. code:: python
from aeon import Measurement
m = Measurement()
for i in xrange(100):
m.start()
# stuff happens here
m.stop()
assert m.calls == 100
print m.total_runtime, m.time_per_call
Installation
------------
Installation is easy as:
.. code:: bash
$ sudo pip install aeon
Rationale
---------
The code has originally been used in a computational physics project
where the typical runtime distribution is very dependent on the problem
at hand. It has proven itself useful for giving a feel for where time is
spent during computation and quickly showing when parts of code went on
a riot. In fact, in that project, it is enabled in production since the
overhead is low.
What sets it apart is the possibility to monitor only specific parts of
the code and optionally have these parts logically grouped (by default,
it will use the class or module names).
There are better alternatives for proper benchmarking, like cProfile.