Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
I was trying to optimize extremely performance sensitive big integer / cryptographic code where somehow I couldn't reach the speed of other Assembly implementations.
It turned out I was initializing an array with this line
Using this line instead, with staticFor being a compile-time loop unroller improved performance by 30%, previously my code took 70 cycles and now it takes 50 cycles.
staticFor i, 0, `N`: # Do NOT use Nim slice/toOpenArray, they are not inlined
`scratchSym`[i] = `a_MR`[i]
(state-of-the art C++ JIT-ed code takes 55 cycles on my machine).
I was trying to optimize extremely performance sensitive big integer / cryptographic code where somehow I couldn't reach the speed of other Assembly implementations.
It turned out I was initializing an array with this line
Using this line instead, with
staticFor
being a compile-time loop unroller improved performance by 30%, previously my code took 70 cycles and now it takes 50 cycles.(state-of-the art C++ JIT-ed code takes 55 cycles on my machine).
Profiling:
C code