Re:A function decorator that rewrites the bytecode to enable...
by simion314 on Tuesday September 21, 2021 @01:10AM
(#28602199)
I had to use GOTO label, once so far, as a way to quickly exit from inside nested loops - you can do it without GOTO but the point was to be efficient(like if you work with the pixel colors of a big image , each extra instruction inside the loops will have a visible time effect).
[ Parent
| on HN ]
Re:A function decorator that rewrites the bytecode to enable...
by noduerme on Tuesday September 21, 2021 @04:46AM
(#28603144)
In a situation like that I would usually define a boolean before entering the top loop, and set that true within once a condition is met, causing all the outer loops to break if that condition is true. I can't imagine there would be a major speed difference in some other way of breaking all the loops to jump to a different line of code.
Re:A function decorator that rewrites the bytecode to enable...
by withinboredom on Tuesday September 21, 2021 @05:29AM
(#28603347)
That means once itβs set to true, all the inner loops would need to at least finish that iteration. That could be a huge speed difference at a minimum or a completely wrong implementation.
Re:A function decorator that rewrites the bytecode to enable...
by simion314 on Tuesday September 21, 2021 @05:40AM
(#28603399)
this means you do a if check each loop, this is bad if you do some say image filter/effect where you work with big loops. end you get some nested if and break inside the code, is much more readable to just jump out.
Re:A function decorator that rewrites the bytecode to enable...
by Dylan16807 on Tuesday September 21, 2021 @06:48AM
(#28603724)
I would argue that having to do that is not in fact a 'proper' loop. Your way and goto are both workarounds for a missing control flow construct.
For gosub, what's the issue? It is a method call.
Re:A function decorator that rewrites the bytecode to enable...
by slightwinder on Tuesday September 21, 2021 @10:05AM
(#28605119)
Pythons for-loop is not working with boolean, so using one would mean to uglify the code. A goto would simplify the workflow by removing 1-2 lines for each additional loop.
Re:A function decorator that rewrites the bytecode to enable...
by zweice on Tuesday September 21, 2021 @01:16AM
(#28602229)
Is that faster than (or comparable to) raising an Error in the inner loop and catching it outside the outer loop?
Re:A function decorator that rewrites the bytecode to enable...
by loa_in_ on Tuesday September 21, 2021 @02:14AM
(#28602443)
Internal error bubbling code is slow and can change from release to release. And it's definitely not intended for the job.
Re:A function decorator that rewrites the bytecode to enable...
by simion314 on Tuesday September 21, 2021 @02:40AM
(#28602554)
probably faster since it was built for this purpose, throwing an error would have to at least create an exception object, then create stack trace and the other setup stuff.
As i said I code for almost 20 years and I only had to use it once so far, but people that maybe work a lot more with stuff that needs a lot of performance might use it much more often.