|
2 | 2 |
|
3 | 3 | # `codetiming` - A flexible, customizable timer for your Python code |
4 | 4 |
|
5 | | -[](https://pypi.org/project/codetiming/) |
6 | | -[](https://pypi.org/project/codetiming/) |
7 | | -[](https://github.com/psf/black) |
| 5 | +[](https://pypi.org/project/codetiming/) |
| 6 | +[](https://pypi.org/project/codetiming/) |
| 7 | +[](https://pypi.org/project/codetiming/) |
| 8 | +[](https://github.com/realpython/codetiming/actions) |
8 | 9 | [](http://mypy-lang.org/) |
9 | 10 | [](https://interrogate.readthedocs.io/) |
10 | | -[](https://circleci.com/gh/realpython/codetiming) |
| 11 | +[](https://github.com/psf/black) |
| 12 | +[](https://mit-license.org/) |
11 | 13 |
|
12 | 14 | Install `codetiming` from PyPI: |
13 | 15 |
|
14 | 16 | ``` |
15 | 17 | $ python -m pip install codetiming |
16 | 18 | ``` |
17 | 19 |
|
18 | | -The source code is [available at GitHub](https://github.com/realpython/codetiming). |
| 20 | +The source code is [available on GitHub](https://github.com/realpython/codetiming). |
19 | 21 |
|
20 | | -For a complete tutorial on how `codetiming` works, see [Python Timer Functions: Three Ways to Monitor Your Code](https://realpython.com/python-timer) on [Real Python](https://realpython.com/). |
| 22 | +For a complete tutorial on `codetiming`, see [Python Timer Functions: Three Ways to Monitor Your Code](https://realpython.com/python-timer) on [Real Python](https://realpython.com/). |
21 | 23 |
|
22 | 24 | ## Basic Usage |
23 | 25 |
|
@@ -50,22 +52,22 @@ You can use `codetiming.Timer` in several different ways: |
50 | 52 |
|
51 | 53 | ## Arguments |
52 | 54 |
|
53 | | -`Timer` accepts the following arguments when it's created, all are optional: |
| 55 | +`Timer` accepts the following arguments when it's created. All arguments are optional: |
54 | 56 |
|
55 | 57 | - **`name`:** An optional name for your timer |
56 | 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"`) |
57 | | -- **`logger`:** A function/callable that takes a string argument, and will report the elapsed time when the logger is stopped (default: `print()`) |
| 59 | +- **`logger`:** A function/callable that takes a string argument and will report the elapsed time when the logger is stopped (default: `print()`) |
58 | 60 |
|
59 | 61 | You can turn off explicit reporting of the elapsed time by setting `logger=None`. |
60 | 62 |
|
61 | | -In the template text, you can also use explicit attributes to refer to the `name` of the timer, or log the elapsed time in `milliseconds`, `seconds` (the default), or `minutes`. For example: |
| 63 | +In the template text, you can also use explicit attributes to refer to the `name` of the timer or log the elapsed time in `milliseconds`, `seconds` (the default), or `minutes`. For example: |
62 | 64 |
|
63 | 65 | ```python |
64 | 66 | t1 = Timer(name="NamedTimer", text="{name}: {minutes:.1f} minutes") |
65 | 67 | t2 = Timer(text="Elapsed time: {milliseconds:.0f} ms") |
66 | 68 | ``` |
67 | 69 |
|
68 | | -Note that the strings used by `text` are **not** f-strings. Instead they are used as templates that will be populated using `.format()` behind the scenes. If you want to combine the `text` template with an f-string, you need to use double braces for the template values: |
| 70 | +Note that the strings used by `text` are **not** f-strings. Instead, they are used as templates that will be populated using `.format()` behind the scenes. If you want to combine the `text` template with an f-string, you need to use double braces for the template values: |
69 | 71 |
|
70 | 72 | ```python |
71 | 73 | t = Timer(text=f"{__file__}: {{:.4f}}") |
@@ -146,6 +148,6 @@ You can also get simple statistics about your named timers. Continuing from the |
146 | 148 | `timers` support `.count()`, `.total()`, `.min()`, `.max()`, `.mean()`, `.median()`, and `.stdev()`. |
147 | 149 |
|
148 | 150 |
|
149 | | -## Acknowledgements |
| 151 | +## Acknowledgments |
150 | 152 |
|
151 | | -`codetiming` is based on a similar module originally developed for the [Midgard Geodesy library](https://kartverket.github.io/midgard/) at the [Norwegian Mapping Authority](https://www.kartverket.no/en/). |
| 153 | +`codetiming` is based on a similar module initially developed for the [Midgard Geodesy library](https://kartverket.github.io/midgard/) at the [Norwegian Mapping Authority](https://www.kartverket.no/en/). |
0 commit comments