830 B
830 B
Timings of CPython Operations
Here are some very rough approximate timings of CPython interpreter operations:
f(1)
(empty function body): 70-90nsf(n=1)
(empty function body): 90-110nso.x
: 30-40nso.f(1)
(empty method body): 80-160nsCls(1)
(initialize attribute in__init__
): 290-330nsx + y
(integers): 20-35nsa[i]
(list) : 20-40ns[i]
(also dealloc): 35-55nsa.append(i)
(list, average over 5 appends): 70nsd[s]
(dict, shared str key): 20nsd[s] = i
(dict, shared str key): 40nsisinstance(x, A)
: 100ns(x, y)
: 20-35nsx, 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