MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/qrfump/pain_and_suffering/hk7w9up/
r/badcode • u/CravenCJK • Nov 11 '21
19 comments sorted by
View all comments
Show parent comment
0
[deleted] — view deleted comment
6 u/CaitaXD Nov 11 '21 edited Nov 11 '21 In the inevitable case in witch this function recives 1 billion calls per second ? 1 u/DeltaJesus Nov 11 '21 Or just because it's better practice? In this specific case it doesn't particularly matter, but better to be consistent imo. 5 u/CaitaXD Nov 11 '21 Err it really depends you can't judge this in a vaccum what if you have 1 trillion indexes an array would be slower if not overflow the stackIm obviously exaggerating and I know you would not make a switch with a trillion cases 2 u/fliguana Nov 27 '21 Compiler will turn this into jump table (array of code pointers), which works faster than the solution you were thinking about.Switches optimize very well.
6
In the inevitable case in witch this function recives 1 billion calls per second ?
1 u/DeltaJesus Nov 11 '21 Or just because it's better practice? In this specific case it doesn't particularly matter, but better to be consistent imo. 5 u/CaitaXD Nov 11 '21 Err it really depends you can't judge this in a vaccum what if you have 1 trillion indexes an array would be slower if not overflow the stackIm obviously exaggerating and I know you would not make a switch with a trillion cases
1
Or just because it's better practice? In this specific case it doesn't particularly matter, but better to be consistent imo.
5 u/CaitaXD Nov 11 '21 Err it really depends you can't judge this in a vaccum what if you have 1 trillion indexes an array would be slower if not overflow the stackIm obviously exaggerating and I know you would not make a switch with a trillion cases
5
Err it really depends you can't judge this in a vaccum what if you have 1 trillion indexes an array would be slower if not overflow the stack
Im obviously exaggerating and I know you would not make a switch with a trillion cases
2
Compiler will turn this into jump table (array of code pointers), which works faster than the solution you were thinking about.
Switches optimize very well.
View all comments
Show parent comment
0
u/[deleted] Nov 11 '21
[deleted] — view deleted comment