r/madeinpython • • Jan 14 '23

Deep-timeit: Time each individual line of a function in python!

Deep-timeit is a module that allows accurate and granular timing of a function in python, and produces a colour-coded heat-map of the results! This can be very useful when your code runs too slowly, and you want to find the bottlenecks!

https://github.com/Yetiowner/Deep-time-it

22 Upvotes

9 comments sorted by

1

u/[deleted] Jan 15 '23

!RemindMe 24 hours

1

u/NoLifeGamer2 Jan 15 '23

This feels vaguely threatening.

1

u/[deleted] Jan 15 '23

haahaha, nah, i just wanted to pick through the code to figure out how it works, but cba today so ill do it at work tomorrow

1

u/NoLifeGamer2 Jan 15 '23

Fair. Be warned, I channeled my inner spaghetti when I wrote that.

1

u/[deleted] Jan 15 '23

perfect.
But fr though, how are you able to get python to investigate each line of a function independently?

1

u/NoLifeGamer2 Jan 15 '23

Basically, I used the inspect module to get the function source code, then inserted timers effectively between each line using time.time(), then used exec to run the string version of the function. Like I said, spaghetti.

1

u/[deleted] Jan 15 '23

oooooh, neat!

1

u/[deleted] Jan 14 '23

!RemindMe 12 hours
I wonder how its able to do this, I wasn't aware that python could break down functions via each line and then do something with that.

1

u/RemindMeBot Jan 14 '23

I will be messaging you in 12 hours on 2023-01-15 10:19:02 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback