January 2020
Intermediate to advanced
532 pages
13h 31m
English
Another use case of macros is to unroll loops into repeating code fragments. Loop unrolling is a performance optimization technique. The premise behind it is that there is always some overhead that is required to execute code in a loop. The reason is that, every time an iteration is finished, the loop must check for a condition and decide whether it should exit or continue with the next iteration. Now, if we know exactly how many times the loop needs to run the code, then we can unroll it by writing out the code in a repeated fashion.
Consider a simple loop as follows:
for i in 1:3 println("hello: ", i)end
We can unroll the loop into three lines of code that do the exact same job:
println("hello: ", 1)println("hello: ", 2) ...Read now
Unlock full access