| 1 |
# Timings of CPython Operations |
| 2 |
|
| 3 |
Here are some *very rough* approximate timings of CPython interpreter |
| 4 |
operations: |
| 5 |
|
| 6 |
* `f(1)` (empty function body): 70-90ns |
| 7 |
* `f(n=1)` (empty function body): 90-110ns |
| 8 |
* `o.x`: 30-40ns |
| 9 |
* `o.f(1)` (empty method body): 80-160ns |
| 10 |
* `Cls(1)` (initialize attribute in `__init__`): 290-330ns |
| 11 |
* `x + y` (integers): 20-35ns |
| 12 |
* `a[i]` (list) : 20-40ns |
| 13 |
* `[i]` (also dealloc): 35-55ns |
| 14 |
* `a.append(i)` (list, average over 5 appends): 70ns |
| 15 |
* `d[s]` (dict, shared str key): 20ns |
| 16 |
* `d[s] = i` (dict, shared str key): 40ns |
| 17 |
* `isinstance(x, A)`: 100ns |
| 18 |
* `(x, y)`: 20-35ns |
| 19 |
* `x, y = t` (tuple expand): 10ns |
| 20 |
|
| 21 |
Note that these results are very imprecise due to many factors, but |
| 22 |
these should give a rough idea of the relative costs of various |
| 23 |
operations. |
| 24 |
|
| 25 |
Details: CPython 3.6.2, Macbook Pro 15" (Mid 2015), macOS Sierra |