%%timeit could use local scope.
See original GitHub issueYou can’t use timeit in a function (which is useful to test variable inputs of several function doing the same things, and plot graphs.
I believe a well placed @needs_local_scope
and modification to timeit should allow that.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Local variables in Python timeit setup - Stack Overflow
I would like to use timeit. timeit with variables that are within the scope it is in, for example: def func(): s1 =...
Read more >Python: Scoping variables to use with timeit - Mark Needham
I've been playing around with Python's timeit library to help benchmark some Neo4j cypher queries but I ran into some problems when trying ......
Read more >How To Use The TimeIt Module in python - Twise Random
The timeIt module is used to test how fast our code is . We can use it to compare different functions or classes...
Read more >timeit — Measure execution time of small code snippets ...
Source code: Lib/timeit.py This module provides a simple way to time small ... The following example shows how the Command-Line Interface can be...
Read more >Python Timeit Module (With Examples) - Pylenin
Approach 2 - Use a list comprehension · It ignores the background processes running on your system, which might have an impact on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was likely refering to the line magic
%timeit
not the cell magic. I tried to make a %timeit, in a function in a for loop. For example:And this timeit would need local scope.
I believe that what I was referring to and inadvertantly have put 2 % sign.
That’s unfortunate. I would have been inclined to hold off from merging the PR in that case. Hopefully not too many people will hit it, though, because it only affects using
%timeit
inside a function, which I think is fairly unusual.That’s a decent idea, but I think we probably shouldn’t pursue it. Timeit goes to some lengths to eliminate as much code as possible between the time measurements and the code to execute, so that the timings are as accurate as possible.