The EASY Way To Time Your Python Code Performance (ft. timeit)

Поділитися
Вставка
  • Опубліковано 3 лис 2024

КОМЕНТАРІ • 19

  • @dihydrogen
    @dihydrogen Рік тому +7

    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

  • @ButchCassidyAndSundanceKid
    @ButchCassidyAndSundanceKid Рік тому +1

    Pretty useful. Thanks.

  • @pawejerzyna5674
    @pawejerzyna5674 Рік тому

    great video, thanks

  • @sauravsharma1085
    @sauravsharma1085 Рік тому

    We can also use Samay module to get execution time and visualization of execution of a function.

  • @davislayton1558
    @davislayton1558 Рік тому

    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 "

  • @eddymoreno5624
    @eddymoreno5624 Рік тому

    I got the utility of using typing in function parameters and returns but specifing the type of everything is too much when is obvius

    • @cerealport2726
      @cerealport2726 3 місяці тому

      so don't do it that way... no one is forcing you to do anything....

  • @bart75_38
    @bart75_38 Рік тому

    Can you make a video on multi prossesing in python? Need to know how to do it So i can same my self 30min a Day.

    • @Indently
      @Indently  Рік тому

      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

  • @chx75
    @chx75 Рік тому +1

    Why is repeat a different function than timeit? They could just make repeat an option in timeit. Damn "typed" programmers.

    • @Indently
      @Indently  Рік тому +2

      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 :)

  • @paljain01
    @paljain01 Рік тому

    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
      @Indently  Рік тому

      Why are you doing these crazy gymnastics when default_timer literally just uses perf_counter? Just curious

    • @paljain01
      @paljain01 Рік тому

      @@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.

  • @gurudevnayak7664
    @gurudevnayak7664 9 місяців тому

    speak english!!!!

    • @Indently
      @Indently  9 місяців тому

      Like British English?