You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add framework for timer startup log statement (#47)
* Add framework for timer startup log statement
* Add initial_text attribute to control start text
* Add default initial_text referencing timer name
* Update CHANGELOG, AUTHORS, and README
* A bit of cleanup and tweaks to existing tests
Co-authored-by: Geir Arne Hjelle <geirarne@gmail.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7
7
8
8
## [Unreleased]
9
9
10
+
### Added
11
+
12
+
-`inital_text` parameter which, when present, will use logger to log that timer has been started (by [Matthew Price](https://github.com/pricemg) in [#47])
13
+
10
14
## [1.3.2] - 2022-10-07
11
15
12
16
### Added
@@ -40,7 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
40
44
41
45
### Changed
42
46
43
-
-`Timer.timers` changed from regular to `dict` to a custom dictionary supporting basic statistics for named timers ([#23]).
47
+
-`Timer.timers` changed from regular `dict` to a custom dictionary supporting basic statistics for named timers ([#23]).
44
48
45
49
46
50
## [1.1.0] - 2020-01-15
@@ -81,3 +85,4 @@ Initial version of `codetiming`. Version 1.0.0 corresponds to the code in the tu
Copy file name to clipboardExpand all lines: README.md
+13-4Lines changed: 13 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,8 @@ You can use `codetiming.Timer` in several different ways:
55
55
`Timer` accepts the following arguments when it's created. All arguments are optional:
56
56
57
57
-**`name`:** An optional name for your timer
58
-
-**`text`:** The text shown when your timer ends. It should contain a `{}` placeholder that will be filled by the elapsed time in seconds (default: `"Elapsed time: {:.4f} seconds"`)
58
+
-**`text`:** The text that's shown when your timer ends. It should contain a `{}` placeholder that will be filled by the elapsed time in seconds (default: `"Elapsed time: {:.4f} seconds"`)
59
+
-**`initial_text`:** Show text when your timer starts. You may provide the string to be logged or`True` to show the default text `"Timer {name} started"` (default: `False`)
59
60
-**`logger`:** A function/callable that takes a string argument and will report the elapsed time when the logger is stopped (default: `print()`)
60
61
61
62
You can turn off explicit reporting of the elapsed time by setting `logger=None`.
You may include a text that should be logged when the timer starts by setting `initial_text`:
93
+
94
+
```python
95
+
t = Timer(initial_text="And so it begins ...")
96
+
```
97
+
98
+
You can also set `initial_text=True` to use a default initial text.
99
+
91
100
92
101
## Capturing the Elapsed Time
93
102
@@ -109,7 +118,7 @@ elapsed_time = t.last
109
118
110
119
Named timers are made available in the class dictionary `Timer.timers`. The elapsed time will accumulate if the same name or same timer is used several times. Consider the following example:
111
120
112
-
```python
121
+
```pycon
113
122
>>> import logging
114
123
>>> from codetiming import Timer
115
124
@@ -133,7 +142,7 @@ The example shows how you can redirect the timer output to the logging module. N
133
142
134
143
You can also get simple statistics about your named timers. Continuing from the example above:
0 commit comments