[2024-12-18] Update README and run.py to reflect new syntax
Also remove GitHub specific links and logo
This commit is contained in:
parent
2a3087ad35
commit
5b2a23d06a
79
README.md
79
README.md
@ -1,10 +1,5 @@
|
||||

|
||||

|
||||
|
||||
# Fast, simple and accurate Python timing. Written in Rust.
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Installation
|
||||
@ -14,40 +9,76 @@ $ python -m pip install tictoc
|
||||
```
|
||||
|
||||
## Usage
|
||||
Import and initialise. **The module must be initialised to be used!**
|
||||
Import.
|
||||
```python
|
||||
import tictoc
|
||||
t = tictoc.init()
|
||||
from tictoc import tic,toc
|
||||
```
|
||||
Begin timing with `tic()`, and stop with `toc()`.
|
||||
If you only want to time one section of code then use `tic() and `toc()` directly. Begin timing with `tic()`, and stop with `toc()`.
|
||||
```python
|
||||
t.tic()
|
||||
tic()
|
||||
# some code
|
||||
t.toc()
|
||||
toc()
|
||||
```
|
||||
When `toc` is called, the results are saved. They can be accessed with the following syntax:
|
||||
A call to `tic()` can be followed with multiple `toc()` calls. Each will print the time elapsed since the most recent `tic()` call.
|
||||
```python
|
||||
t.results.{unit}
|
||||
tic()
|
||||
time.sleep(3)
|
||||
toc()
|
||||
# >>> The elapsed time was 3.000132333 seconds.
|
||||
time.sleep(3)
|
||||
toc()
|
||||
# >>> The elapsed time was 6.000383124 seconds.
|
||||
```
|
||||
For more complex timing operations, you can assign the output of `tic()` and pass it as an input to `toc()`.
|
||||
> [!NOTE]
|
||||
> This syntax cannot be used interchangeably with the default syntax above. Any call to `tic()` resets the global timer.
|
||||
```python
|
||||
firstTic = tic()
|
||||
time.sleep(3)
|
||||
secondTic = tic()
|
||||
time.sleep(1)
|
||||
toc(firstTic)
|
||||
# >>> The elapsed time was 4.000317251 seconds.
|
||||
time.sleep(3)
|
||||
toc(secondTic)
|
||||
# >>> The elapsed time was 4.000312568 seconds.
|
||||
```
|
||||
Any call to `toc()` will print the elapsed time in seconds. You can save the results with full precision by assigning the output of `toc()`.
|
||||
```python
|
||||
tic()
|
||||
# some code
|
||||
results = toc()
|
||||
```
|
||||
The available units are:
|
||||
```python
|
||||
t.results.nanos # u128
|
||||
t.results.micros # u128
|
||||
t.results.millis # u128
|
||||
t.results.seconds # f64
|
||||
results.nanos # u128
|
||||
results.micros # u128
|
||||
results.millis # u128
|
||||
results.seconds # f64
|
||||
```
|
||||
|
||||
## Full example
|
||||
```python
|
||||
import time
|
||||
from tictoc import tic,toc
|
||||
|
||||
import tictoc
|
||||
t = tictoc.init()
|
||||
|
||||
t.tic() # start timing
|
||||
tic() # start timing
|
||||
time.sleep(3) # sleep for 3 seconds
|
||||
t.toc() # stop timing
|
||||
toc() # stop timing
|
||||
# >>> The elapsed time was 3.000132333 seconds.
|
||||
|
||||
print(t.results.seconds)
|
||||
# >>> 3.000457715
|
||||
firstTic = tic()
|
||||
time.sleep(3)
|
||||
secondTic = tic()
|
||||
time.sleep(1)
|
||||
toc(firstTic)
|
||||
# >>> The elapsed time was 4.000317251 seconds.
|
||||
time.sleep(3)
|
||||
toc(secondTic)
|
||||
# >>> The elapsed time was 4.000312568 seconds.
|
||||
|
||||
tic()
|
||||
results = toc()
|
||||
print(results.nanos)
|
||||
# >>> 2825
|
||||
```
|
||||
|
25
run.py
25
run.py
@ -1,11 +1,22 @@
|
||||
import time
|
||||
from tictoc import tic,toc
|
||||
|
||||
import tictoc
|
||||
tic() # start timing
|
||||
time.sleep(3) # sleep for 3 seconds
|
||||
toc() # stop timing
|
||||
# >>> The elapsed time was 3.000132333 seconds.
|
||||
|
||||
t = tictoc.init()
|
||||
firstTic = tic()
|
||||
time.sleep(3)
|
||||
secondTic = tic()
|
||||
time.sleep(1)
|
||||
toc(firstTic)
|
||||
# >>> The elapsed time was 4.000317251 seconds.
|
||||
time.sleep(3)
|
||||
toc(secondTic)
|
||||
# >>> The elapsed time was 4.000312568 seconds.
|
||||
|
||||
t.tic() # start timing
|
||||
time.sleep(3) # sleep for 3 seconds
|
||||
t.toc() # stop timing
|
||||
|
||||
print(t.results.seconds)
|
||||
tic()
|
||||
results = toc()
|
||||
print(results.nanos)
|
||||
# >>> 2825
|
||||
|
Loading…
x
Reference in New Issue
Block a user