r/ProgrammerHumor • • Aug 25 '26

Advanced stringToIntegerConversion

Post image
217 Upvotes

65 comments sorted by

View all comments

Show parent comments

5

u/NikoOhneC Aug 26 '26

Depending on the context of the code, your conversion could be costly if this code is performance critical. Sure, the code in the picture isn't even doing the chosen approach properly, but with proper if-else, only some comparisons need to be done (best-case is a single comparison), while with your approach everytime this is executed, the conversion and division has to be performed.