Skip to content

Commit

Permalink
Update notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas1312 committed Mar 21, 2024
1 parent 75c3d01 commit 662d71d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions base/science-tech-maths/programming/languages/python/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- [Mutable default arguments](#mutable-default-arguments)
- [lru\_cache or cache on class methods](#lru_cache-or-cache-on-class-methods)
- [Timing code](#timing-code)
- [Caching code](#caching-code)
- [Modules import time](#modules-import-time)
- [Wheels](#wheels)
- [Virtualenv](#virtualenv)
Expand Down Expand Up @@ -1259,6 +1260,16 @@ print(timeit.timeit(my_function, number=100000))

Don't use `time.time()`! It's not monotonic! Use `time.monotonic_ns()` instead to measure a time difference.

## Caching code

On expensive functions, you can use `functools.lru_cache` to cache the result of the function for the same arguments:

```python
from pydantic import TypeAdapter

TypeAdapter = lru_cache(TypeAdapter)
```

## Modules import time

```bash
Expand Down

0 comments on commit 662d71d

Please sign in to comment.