![]() |
Is there a list somewhere that explains how to optimize? - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16) +---- Thread: Is there a list somewhere that explains how to optimize? (/showthread.php?tid=1435) |
Is there a list somewhere that explains how to optimize? - maeloterkim - 09-15-2021 Hi Is there a list somewhere that explains how to optimize? i explain Normally in compilers if you put the code in one way it is more efficient than if you put the code in another way For example you can do variable ++ or variable = variable + 1 or maybe if you use local variables it is more efficient than if you use global variables perhaps the compiler translates with fewer bytes and more efficiently one way or another Is there somewhere a recomended list of tricks to write a more efficient syntax that translates better to assembler and uses less memory and fewer bytes? RE: Is there a list somewhere that explains how to optimize? - boriel - 09-16-2021 No, unfortunately there is not. You might search in this forum and might find some questions and answers. The reason for this is people will go to write "Bad code" just for speed. The compiler goes better and better optimizing. For example: variable = variable + 1 will be internally converted to variable++ by the compiler. Multiplying or dividing integer by powers of 2 will become << and >> internally. etc... There are still many optimizations pending to be implemented but they will eventually arrive. Two tips: If possible "cache" value in variables: Code: FOR i = 1 to a * x + 3 Code: LET last = a * x + 1 Code: IF a = 1 THEN This is equivalent to a switch( ) (SELECT CASE) in other languages, and is faster. Anyway if you find something running slow, just ask. RE: Is there a list somewhere that explains how to optimize? - maeloterkim - 09-16-2021 (09-16-2021, 06:59 AM)boriel Wrote: No, unfortunately there is not. You might search in this forum and might find some questions and answers. Thanks If we know how the compiler does better and fast things we will do better programs ![]() maybe you can use this post as library of tips for the compiler or create another post for this thing and just write it here any tip about the compiler as it arises in the forum This way will be more easy to found the compiler tricks |