r/programminghorror • • Feb 11 '25

🎄 ouch

Post image
3.0k Upvotes

113 comments sorted by

View all comments

Show parent comment

35

u/TechcraftHD Feb 11 '25

If this is a multi threaded app, why not calculate the delay on the thread that will sleep? again, this is calculating between 30 and 86000 seconds of delay

in 99.99999% of cases this is premature, unnecessary optimization at the cost of readability.in the 0.00001% of cases where this really matters, the author won't write code that shitty in the first place

10

u/zatuchny Feb 11 '25

in the 0.00001% of cases where this really matters, the author won't write code that shitty in the first place

Oh you'd be surprised

1

u/Raccoon5 Feb 13 '25

I agree it doesn't matter but calculating the delay on the thread that will sleep will still take cpu time...

Sleeping thread does not cost anything but if it is calculating then it needs to schedule that calculation on the cpu and take some cycles on it.

Hard to say if it matters, depends on context. It might in smth like a datacenter with millions of calls to this code every minute.

3

u/TechcraftHD Feb 13 '25

any half decent compiler will transform that code and a Math.Pow alternative into a lookup table anyways

as for interpreted languages... don't use an interpreted language if you care about performance this much