This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: make timeit module accept files
Type: enhancement Stage: patch review
Components: Library (Lib) Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: CCLDArjun, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2022-01-24 07:08 by CCLDArjun, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30844 open CCLDArjun, 2022-01-24 07:12
Messages (4)
msg411448 - (view) Author: Arjun (CCLDArjun) * Date: 2022-01-24 07:08
currently, timeit accepts programs line by line as commandline arguments. 

it would be convenient to give it a program as a file to benchmark.
msg411455 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-01-24 08:50
This module provides a simple way to time small bits of Python code.

What problem are you trying to solve.
msg411515 - (view) Author: Arjun (CCLDArjun) * Date: 2022-01-24 21:17
I was modifying the try/except/finally/else code generation and wanted to run my own benchmarks.

It's cumbersome to edit them in a command to test different variations, especially when you have to indent.
msg411982 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-01-28 09:19
Usually, when you benchmark a non-trivial piece of code, you need also to specify a setup code. If the benchmarked code is large enough to be read from a file, the setup code should be read from a file too.

The common practice is to write the benchmarked code as a function which can be imported and repeatedly executed.

$ python -m timeit -s 'from mybench import test' 'test()'
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90658
2022-01-28 09:19:19serhiy.storchakasetmessages: + msg411982
2022-01-24 21:17:13CCLDArjunsetmessages: + msg411515
2022-01-24 08:50:03serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg411455
2022-01-24 07:12:22CCLDArjunsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29026
2022-01-24 07:08:00CCLDArjuncreate