Mercurial > hgrepos > Python > libs > ConfigMix
view tests/_perf_lookups.py @ 654:0d6673d06c2c
Add support for using "tomllib" (in Python's stdlib since 3.11) and "tomli" TOML packages.
They are preferred if they are found to be installed.
But note that the declared dependency for the "toml" extra nevertheless
is the "toml" package. Because it is available for all supported Python
versions.
So use Python 3.11+ or install "tomli" manually if you want to use the
alternate packages.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 19 May 2022 22:10:59 +0200 |
| parents | 60683361ebed |
| children |
line wrap: on
line source
from __future__ import print_function import timeit setup=''' XGLOBAL= 5 class A: xclass = 5 def __init__(self): self.xinstance = 5 def f1(self): xlocal = 5 x = self.xinstance def f2(self): xlocal = 5 x = A.xclass def f3(self): xlocal = 5 x = XGLOBAL def f4(self): xlocal = 5 x = xlocal def f5(self): xlocal = 5 x = self.xclass a = A() ''' num = 300000000 num = 90000000 print('access via instance variable: %.3f' % timeit.timeit('a.f1()', setup=setup, number=num) ) print('access via class variable (via classname): %.3f' % timeit.timeit('a.f2()', setup=setup, number=num) ) print('access via class variable (via self): %.3f' % timeit.timeit('a.f5()', setup=setup, number=num) ) print('access via module variable: %.3f' % timeit.timeit('a.f3()', setup=setup, number=num) ) print('access via local variable: %.3f' % timeit.timeit('a.f4()', setup=setup, number=num) )
