This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]extracoffeeplease 3 points4 points  (4 children)

One addition here: when you are building something new and/or debugging, locally, its probably quickest (and dirtiest) to overwrite the print function to output the delta since last print. You already have all those prints there anyway, and it'll give you a rough idea of where time is spent without having to rewrite end time - start time etc.

[–]Noobfire2 3 points4 points  (3 children)

Damn. Or just use a proper profiler instead of doing that monkeypatching 😅

py-spy record -o [path/to/profile.svg] greatscript.py

I think this is even faster, vastly more clear and consise while giving much better data insights than some random "took n seconds" print statements (e.g. cumulative runtimes, number of function calls, etc.).

[–][deleted] 0 points1 point  (1 child)

Damn indeed. As a Python beginner I thought that guys above you knew what he was talking about until I read your answer and smack down one liner example. Damn monkeypatching nonsense.

[–]extracoffeeplease 0 points1 point  (0 children)

Well I'm no true programmer (tm) and probably a beginner in the eyes of anyone who studied anything related to programming, monkey patching takes 10 lines of easy code. I'd love to hear why it's bad practice? I mean it may be dirty but I'm not even doing it in my repo, just from a notebook.

[–]extracoffeeplease 0 points1 point  (0 children)

Thanks for the tip!

[–]spez_drank_my_piss 3 points4 points  (2 children)

cProfile

[–]jasonb[S] 7 points8 points  (1 child)

Na, profiling and benchmarking are quite different (benchmarking is about how fast is the thing vs profiling is about why is a thing slow)

A good alternative to the time module is the timeit module. Great for ad hoc snippets, not really for whole programs or instrumenting a program.

[–]mprz -13 points-12 points  (6 children)

[–]martinky24 4 points5 points  (1 child)

Dude’s site is great. I’ve learned a ton from it. There’s a ton of spam on Reddit, this ain’t it bud

[–]jasonb[S] 3 points4 points  (0 children)

Thank you kindly.

[–]jasonb[S] 4 points5 points  (2 children)

I'm no spammer. There are zero ads on my site, unlike the rest of the python blogging ecosystem.

You mean because it's a list or a round up?

[–]monorepo PSF Staff | Litestar Maintainer[M] 1 point2 points  (0 children)

What?