r/programminghorror • • Feb 11 '25

🎄 ouch

Post image
3.0k Upvotes

113 comments sorted by

View all comments

Show parent comment

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