when it comes to modules with timeit, i've found that passing globals=globals() could be a good alternative to setup parameter, especially when there are many modules to worry about in your timeit. although this would require you to actually import the modules in your python file, i'm sure you would have done that already. but you also would be able to use variables in the global scope edit: it has been 8 minutes in. this is mentioned. i shall now eat my legs, for that would be the only way to correct this mistake
Yeah I found that interesting as well. Couldn’t tell you why they did that. Maybe it added far too much complexity to timeit. Or maybe they wanted to make sure that users understood that one returns a list of floats, while the other just returns a float. Those are just my ideas :)
I got ths error when running your code in the globals section of the video: " def list_generate_random(amount: int) -> list[float]: TypeError: 'type' object is not subscriptable "
Unlikely I will bring it to the channel any time in the near future, but if you're more than welcome to learn it from my full Python course on indently.io
i used timeit's default_timer from timeit import default_timer as timer start = timer() """some statements talking to DB""" print(f"Time Taken: {timer()-start} sec.")
@@Indently no specific reason. I got it from a stackoverflow answer using this since like this only. maybe because default_timer feels natural than perf_counter. good to know I can do this from the time module only. thx.