/opt/alt/python311/lib64/python3.11
NameSizeModeActions
asyncio/-0755rm
collections/-0755rm
concurrent/-0755rm
config-3.11-x86_64-linux-gnu/-0755rm
ctypes/-0755rm
curses/-0755rm
dbm/-0755rm
distutils/-0755rm
email/-0755rm
encodings/-0755rm
ensurepip/-0755rm
html/-0755rm
http/-0755rm
importlib/-0755rm
json/-0755rm
lib-dynload/-0755rm
lib2to3/-0755rm
logging/-0755rm
multiprocessing/-0755rm
pydoc_data/-0755rm
re/-0755rm
site-packages/-0755rm
sqlite3/-0755rm
tomllib/-0755rm
unittest/-0755rm
urllib/-0755rm
venv/-0755rm
wsgiref/-0755rm
xml/-0755rm
xmlrpc/-0755rm
zoneinfo/-0755rm
__phello__/-0755rm
__pycache__/-0755rm
abc.py65380644editdlrm
aifc.py342110644editdlrm
antigravity.py5000644editdlrm
argparse.py1002830644editdlrm
ast.py614440644editdlrm
asynchat.py115700644editdlrm
asyncore.py203100644editdlrm
base64.py210410755editdlrm
bdb.py324630644editdlrm
bisect.py31350644editdlrm
bz2.py118470644editdlrm
calendar.py247310644editdlrm
cgi.py344320755editdlrm
cgitb.py124210644editdlrm
chunk.py55000644editdlrm
cmd.py148730644editdlrm
code.py106220644editdlrm
codecs.py371500644editdlrm
codeop.py59070644editdlrm
colorsys.py40620644editdlrm
compileall.py202520644editdlrm
configparser.py556600644editdlrm
contextlib.py274140644editdlrm
contextvars.py1290644editdlrm
copy.py86810644editdlrm
copyreg.py76770644editdlrm
cProfile.py63590755editdlrm
crypt.py39130644editdlrm
csv.py160300644editdlrm
dataclasses.py584720644editdlrm
datetime.py918320644editdlrm
decimal.py3200644editdlrm
difflib.py833080644editdlrm
dis.py289060644editdlrm
doctest.py1062970644editdlrm
enum.py795830644editdlrm
filecmp.py101780644editdlrm
fileinput.py157140644editdlrm
fnmatch.py59990644editdlrm
fractions.py286770644editdlrm
ftplib.py358150644editdlrm
functools.py384130644editdlrm
genericpath.py49750644editdlrm
getopt.py74890644editdlrm
getpass.py59900644editdlrm
gettext.py213200644editdlrm
glob.py87320644editdlrm
graphlib.py96560644editdlrm
gzip.py240740644editdlrm
hashlib.py117650644editdlrm
heapq.py230240644editdlrm
hmac.py77160644editdlrm
imaplib.py552170644editdlrm
imghdr.py39520644editdlrm
imp.py106060644editdlrm
inspect.py1234190644editdlrm
io.py43200644editdlrm
ipaddress.py791240644editdlrm
keyword.py10610644editdlrm
LICENSE.txt139360644editdlrm
linecache.py56490644editdlrm
locale.py790950644editdlrm
lzma.py132770644editdlrm
mailbox.py788300644editdlrm
mailcap.py93690644editdlrm
mimetypes.py229620644editdlrm
modulefinder.py236990644editdlrm
netrc.py69290644editdlrm
nntplib.py410870644editdlrm
ntpath.py302220644editdlrm
nturl2path.py28870644editdlrm
numbers.py103480644editdlrm
opcode.py104470644editdlrm
operator.py109650644editdlrm
optparse.py603690644editdlrm
os.py395300644editdlrm
pathlib.py485660644editdlrm
pdb.py641860755editdlrm
pickle.py651320644editdlrm
pickletools.py938610644editdlrm
pipes.py89780644editdlrm
pkgutil.py246380644editdlrm
platform.py422870755editdlrm
plistlib.py283540644editdlrm
poplib.py151980644editdlrm
posixpath.py170130644editdlrm
pprint.py245830644editdlrm
profile.py228960755editdlrm
pstats.py293560644editdlrm
pty.py63170644editdlrm
pyclbr.py113960644editdlrm
pydoc.py1126640755editdlrm
py_compile.py78370644editdlrm
queue.py114960644editdlrm
quopri.py72810755editdlrm
random.py321620644editdlrm
reprlib.py54370644editdlrm
rlcompleter.py78270644editdlrm
runpy.py131590644editdlrm
sched.py63510644editdlrm
secrets.py20280644editdlrm
selectors.py196710644editdlrm
shelve.py85600644editdlrm
shlex.py135010644editdlrm
shutil.py565170644editdlrm
signal.py24950644editdlrm
site.py229870644editdlrm
smtpd.py311750755editdlrm
smtplib.py454310755editdlrm
sndhdr.py74480644editdlrm
socket.py375570644editdlrm
socketserver.py275860644editdlrm
sre_compile.py2310644editdlrm
sre_constants.py2320644editdlrm
sre_parse.py2290644editdlrm
ssl.py543050644editdlrm
stat.py54850644editdlrm
statistics.py477050644editdlrm
string.py117860644editdlrm
stringprep.py129170644editdlrm
struct.py2570644editdlrm
subprocess.py887250644editdlrm
sunau.py184800644editdlrm
symtable.py103680644editdlrm
sysconfig.py303150644editdlrm
tabnanny.py113120755editdlrm
tarfile.py1078760755editdlrm
telnetlib.py233010644editdlrm
tempfile.py318730644editdlrm
textwrap.py197180644editdlrm
this.py10030644editdlrm
threading.py582310644editdlrm
timeit.py135320755editdlrm
token.py23860644editdlrm
tokenize.py263360644editdlrm
trace.py291960755editdlrm
traceback.py405470644editdlrm
tracemalloc.py180470644editdlrm
tty.py8790644editdlrm
types.py100670644editdlrm
typing.py1209510644editdlrm
uu.py73410644editdlrm
uuid.py275970644editdlrm
warnings.py211100644editdlrm
wave.py218180644editdlrm
weakref.py215130644editdlrm
webbrowser.py251490755editdlrm
xdrlib.py59770644editdlrm
zipapp.py75350644editdlrm
zipfile.py937880644editdlrm
zipimport.py308970644editdlrm
_aix_support.py33890644editdlrm
_bootsubprocess.py26750644editdlrm
_collections_abc.py301930644editdlrm
_compat_pickle.py87610644editdlrm
_compression.py56810644editdlrm
_markupbase.py146530644editdlrm
_osx_support.py220230644editdlrm
_pydecimal.py2292020644editdlrm
_pyio.py941930644editdlrm
_py_abc.py61890644editdlrm
_sitebuiltins.py31280644editdlrm
_strptime.py251750644editdlrm
_sysconfigdata_d_linux_x86_64-linux-gnu.py588780644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.py596450644editdlrm
_threading_local.py72200644editdlrm
_weakrefset.py58930644editdlrm
__future__.py52180644editdlrm
__hello__.py2270644editdlrm
Edit: /opt/alt/python311/lib64/python3.11/timeit.py (13532B)
#! /opt/alt/python311/bin/python3.11 """Tool for measuring execution time of small code snippets. This module avoids a number of common traps for measuring execution times. See also Tim Peters' introduction to the Algorithms chapter in the Python Cookbook, published by O'Reilly. Library usage: see the Timer class. Command line usage: python timeit.py [-n N] [-r N] [-s S] [-p] [-h] [--] [statement] Options: -n/--number N: how many times to execute 'statement' (default: see below) -r/--repeat N: how many times to repeat the timer (default 5) -s/--setup S: statement to be executed once initially (default 'pass'). Execution time of this setup statement is NOT timed. -p/--process: use time.process_time() (default is time.perf_counter()) -v/--verbose: print raw timing results; repeat for more digits precision -u/--unit: set the output time unit (nsec, usec, msec, or sec) -h/--help: print this usage message and exit --: separate options from statement, use when statement starts with - statement: statement to be timed (default 'pass') A multi-line statement may be given by specifying each line as a separate argument; indented lines are possible by enclosing an argument in quotes and using leading spaces. Multiple -s options are treated similarly. If -n is not given, a suitable number of loops is calculated by trying increasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the total time is at least 0.2 seconds. Note: there is a certain baseline overhead associated with executing a pass statement. It differs between versions. The code here doesn't try to hide it, but you should be aware of it. The baseline overhead can be measured by invoking the program without arguments. Classes: Timer Functions: timeit(string, string) -> float repeat(string, string) -> list default_timer() -> float """ import gc import itertools import sys import time __all__ = ["Timer", "timeit", "repeat", "default_timer"] dummy_src_name = "" default_number = 1000000 default_repeat = 5 default_timer = time.perf_counter _globals = globals # Don't change the indentation of the template; the reindent() calls # in Timer.__init__() depend on setup being indented 4 spaces and stmt # being indented 8 spaces. template = """ def inner(_it, _timer{init}): {setup} _t0 = _timer() for _i in _it: {stmt} pass _t1 = _timer() return _t1 - _t0 """ def reindent(src, indent): """Helper to reindent a multi-line statement.""" return src.replace("\n", "\n" + " " * indent) class Timer: """Class for timing execution speed of small code snippets. The constructor takes a statement to be timed, an additional statement used for setup, and a timer function. Both statements default to 'pass'; the timer function is platform-dependent (see module doc string). If 'globals' is specified, the code will be executed within that namespace (as opposed to inside timeit's namespace). To measure the execution time of the first statement, use the timeit() method. The repeat() method is a convenience to call timeit() multiple times and return a list of results. The statements may contain newlines, as long as they don't contain multi-line string literals. """ def __init__(self, stmt="pass", setup="pass", timer=default_timer, globals=None): """Constructor. See class doc string.""" self.timer = timer local_ns = {} global_ns = _globals() if globals is None else globals init = '' if isinstance(setup, str): # Check that the code can be compiled outside a function compile(setup, dummy_src_name, "exec") stmtprefix = setup + '\n' setup = reindent(setup, 4) elif callable(setup): local_ns['_setup'] = setup init += ', _setup=_setup' stmtprefix = '' setup = '_setup()' else: raise ValueError("setup is neither a string nor callable") if isinstance(stmt, str): # Check that the code can be compiled outside a function compile(stmtprefix + stmt, dummy_src_name, "exec") stmt = reindent(stmt, 8) elif callable(stmt): local_ns['_stmt'] = stmt init += ', _stmt=_stmt' stmt = '_stmt()' else: raise ValueError("stmt is neither a string nor callable") src = template.format(stmt=stmt, setup=setup, init=init) self.src = src # Save for traceback display code = compile(src, dummy_src_name, "exec") exec(code, global_ns, local_ns) self.inner = local_ns["inner"] def print_exc(self, file=None): """Helper to print a traceback from the timed code. Typical use: t = Timer(...) # outside the try/except try: t.timeit(...) # or t.repeat(...) except: t.print_exc() The advantage over the standard traceback is that source lines in the compiled template will be displayed. The optional file argument directs where the traceback is sent; it defaults to sys.stderr. """ import linecache, traceback if self.src is not None: linecache.cache[dummy_src_name] = (len(self.src), None, self.src.split("\n"), dummy_src_name) # else the source is already stored somewhere else traceback.print_exc(file=file) def timeit(self, number=default_number): """Time 'number' executions of the main statement. To be precise, this executes the setup statement once, and then returns the time it takes to execute the main statement a number of times, as float seconds if using the default timer. The argument is the number of times through the loop, defaulting to one million. The main statement, the setup statement and the timer function to be used are passed to the constructor. """ it = itertools.repeat(None, number) gcold = gc.isenabled() gc.disable() try: timing = self.inner(it, self.timer) finally: if gcold: gc.enable() return timing def repeat(self, repeat=default_repeat, number=default_number): """Call timeit() a few times. This is a convenience function that calls the timeit() repeatedly, returning a list of results. The first argument specifies how many times to call timeit(), defaulting to 5; the second argument specifies the timer argument, defaulting to one million. Note: it's tempting to calculate mean and standard deviation from the result vector and report these. However, this is not very useful. In a typical case, the lowest value gives a lower bound for how fast your machine can run the given code snippet; higher values in the result vector are typically not caused by variability in Python's speed, but by other processes interfering with your timing accuracy. So the min() of the result is probably the only number you should be interested in. After that, you should look at the entire vector and apply common sense rather than statistics. """ r = [] for i in range(repeat): t = self.timeit(number) r.append(t) return r def autorange(self, callback=None): """Return the number of loops and time taken so that total time >= 0.2. Calls the timeit method with increasing numbers from the sequence 1, 2, 5, 10, 20, 50, ... until the time taken is at least 0.2 second. Returns (number, time_taken). If *callback* is given and is not None, it will be called after each trial with two arguments: ``callback(number, time_taken)``. """ i = 1 while True: for j in 1, 2, 5: number = i * j time_taken = self.timeit(number) if callback: callback(number, time_taken) if time_taken >= 0.2: return (number, time_taken) i *= 10 def timeit(stmt="pass", setup="pass", timer=default_timer, number=default_number, globals=None): """Convenience function to create Timer object and call timeit method.""" return Timer(stmt, setup, timer, globals).timeit(number) def repeat(stmt="pass", setup="pass", timer=default_timer, repeat=default_repeat, number=default_number, globals=None): """Convenience function to create Timer object and call repeat method.""" return Timer(stmt, setup, timer, globals).repeat(repeat, number) def main(args=None, *, _wrap_timer=None): """Main program, used when run as a script. The optional 'args' argument specifies the command line to be parsed, defaulting to sys.argv[1:]. The return value is an exit code to be passed to sys.exit(); it may be None to indicate success. When an exception happens during timing, a traceback is printed to stderr and the return value is 1. Exceptions at other times (including the template compilation) are not caught. '_wrap_timer' is an internal interface used for unit testing. If it is not None, it must be a callable that accepts a timer function and returns another timer function (used for unit testing). """ if args is None: args = sys.argv[1:] import getopt try: opts, args = getopt.getopt(args, "n:u:s:r:tcpvh", ["number=", "setup=", "repeat=", "time", "clock", "process", "verbose", "unit=", "help"]) except getopt.error as err: print(err) print("use -h/--help for command line help") return 2 timer = default_timer stmt = "\n".join(args) or "pass" number = 0 # auto-determine setup = [] repeat = default_repeat verbose = 0 time_unit = None units = {"nsec": 1e-9, "usec": 1e-6, "msec": 1e-3, "sec": 1.0} precision = 3 for o, a in opts: if o in ("-n", "--number"): number = int(a) if o in ("-s", "--setup"): setup.append(a) if o in ("-u", "--unit"): if a in units: time_unit = a else: print("Unrecognized unit. Please select nsec, usec, msec, or sec.", file=sys.stderr) return 2 if o in ("-r", "--repeat"): repeat = int(a) if repeat <= 0: repeat = 1 if o in ("-p", "--process"): timer = time.process_time if o in ("-v", "--verbose"): if verbose: precision += 1 verbose += 1 if o in ("-h", "--help"): print(__doc__, end=' ') return 0 setup = "\n".join(setup) or "pass" # Include the current directory, so that local imports work (sys.path # contains the directory of this script, rather than the current # directory) import os sys.path.insert(0, os.curdir) if _wrap_timer is not None: timer = _wrap_timer(timer) t = Timer(stmt, setup, timer) if number == 0: # determine number so that 0.2 <= total time < 2.0 callback = None if verbose: def callback(number, time_taken): msg = "{num} loop{s} -> {secs:.{prec}g} secs" plural = (number != 1) print(msg.format(num=number, s='s' if plural else '', secs=time_taken, prec=precision)) try: number, _ = t.autorange(callback) except: t.print_exc() return 1 if verbose: print() try: raw_timings = t.repeat(repeat, number) except: t.print_exc() return 1 def format_time(dt): unit = time_unit if unit is not None: scale = units[unit] else: scales = [(scale, unit) for unit, scale in units.items()] scales.sort(reverse=True) for scale, unit in scales: if dt >= scale: break return "%.*g %s" % (precision, dt / scale, unit) if verbose: print("raw times: %s" % ", ".join(map(format_time, raw_timings))) print() timings = [dt / number for dt in raw_timings] best = min(timings) print("%d loop%s, best of %d: %s per loop" % (number, 's' if number != 1 else '', repeat, format_time(best))) best = min(timings) worst = max(timings) if worst >= best * 4: import warnings warnings.warn_explicit("The test results are likely unreliable. " "The worst time (%s) was more than four times " "slower than the best time (%s)." % (format_time(worst), format_time(best)), UserWarning, '', 0) return None if __name__ == "__main__": sys.exit(main())