3 ms·
The optimizations the compiler can do because of the "var" the author added in the nim version of the first example should be also possible without it. Because
by mg 2y ago
The optimizations the compiler can do because of the "var" the author added in the nim version of the first example should be also possible without it. Because Python defines variables as local or global at compile time.
The code looks like they avoided that by putting the code into the global scope?
If the code of the first example is what the author really ran, than he got a speed penalty for running the loop in the global scope.
One might consider it a bit of a quirk that Python code runs slower in the global scope. But in practice, it rarely matters. As a script with just a loop and no functions (not even a main function) is so rare.