On Sun, 10 Jan 2021 at 19:24, Chris Angelico <[email protected]> wrote: > > On Mon, Jan 11, 2021 at 6:06 AM Paul Moore <[email protected]> wrote: > > > > On 2021-01-10 at 18:38:12 +0100, > > Alex Prengère <[email protected]> wrote: > > > 3. Use timeit. The scripts have no side effects so repeating their > > > execution the way timeit does, works for me. The only issue is that, > > > as far as I know, timeit only allows statements as input parameters, > > > not the whole script, like for example: > > > $ python -m timeit --script script.py > > > > There's always > > > > py -m timeit -s "from pathlib import Path; data = > > Path('your_script.py').read_text()" "exec(data, globals())" > > > > Depending on what's being measured, that might not be an accurate > measurement. After the first execution, all imports will be resolved > out of sys.modules.
Obviously, yes. The point here is mainly that there's a few ways of doing what the OP asked, and which is better depends on precisely what they want (which they didn't state in detail). As regards the suggestion of adding this functionality to the timeit module, the fact that there *are* multiple options with different trade-offs is precisely why building one particular choice in as "the way to do it" is probably a mistake. Paul _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/GDNXAX6EUFMWD2JHLYYHUHEP2WFEXXIN/ Code of Conduct: http://python.org/psf/codeofconduct/
