File: cpython-timings.md

package info (click to toggle)
mypy 1.15.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 20,576 kB
  • sloc: python: 105,159; cpp: 11,380; ansic: 6,629; makefile: 247; sh: 20
file content (25 lines) | stat: -rw-r--r-- 830 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Timings of CPython Operations

Here are some *very rough* approximate timings of CPython interpreter
operations:

* `f(1)` (empty function body): 70-90ns
* `f(n=1)` (empty function body): 90-110ns
* `o.x`: 30-40ns
* `o.f(1)` (empty method body): 80-160ns
* `Cls(1)` (initialize attribute in `__init__`): 290-330ns
* `x + y` (integers): 20-35ns
* `a[i]` (list) : 20-40ns
* `[i]` (also dealloc): 35-55ns
* `a.append(i)` (list, average over 5 appends): 70ns
* `d[s]` (dict, shared str key): 20ns
* `d[s] = i` (dict, shared str key): 40ns
* `isinstance(x, A)`: 100ns
* `(x, y)`: 20-35ns
* `x, y = t` (tuple expand): 10ns

Note that these results are very imprecise due to many factors, but
these should give a rough idea of the relative costs of various
operations.

Details: CPython 3.6.2, Macbook Pro 15" (Mid 2015), macOS Sierra