utils: Change gcd function from recursive to interative - #138
Conversation
It'd be faster to use interative implementation than recursive one.
|
I agree that the iterative version could be faster, but apparently it's not relevant. So let's test this. The worst-case clearly is large numbers, and occurs when the ratio between a and b is close to the golden ratio. (Intuition: if the ration is very large, then the first step reduces a and b very quickly because the modulo factor is so large. If the ratio is very small, then the modulo remainder cannot be big, so the first step again reduces a nad b very quickly.) One can just compile this with the same options as tgl will be compiled, and run some experiments. As you can see, it doesn't really make a difference, and actually looks like the recursive version is a bit faster, if at all. Also note that the stack will reach at most a depth of The long wait on startup is more likely due to |

It'd be faster to use interative implementation than recursive one.