On Sun, 10 Jan 2021 at 19:24, Chris Angelico <ros...@gmail.com> wrote:
>
> On Mon, Jan 11, 2021 at 6:06 AM Paul Moore <p.f.mo...@gmail.com> wrote:
> >
> > On 2021-01-10 at 18:38:12 +0100,
> > Alex Prengère <alexpreng...@gmail.com> 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 -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GDNXAX6EUFMWD2JHLYYHUHEP2WFEXXIN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to