On my machine
    
    
    $ nim c -d:danger -d:lto --listcmd reverse.nim
    ......................................................................
    $ time ./reverse
    
    real    0m31.493s
    user    0m31.491s
    sys     0m0.001s
    $ nim c -d:danger -d:lto --listcmd -d:faster reverse.nim
    ......................................................................
    $ time ./reverse
    
    real    0m3.487s
    user    0m3.485s
    sys     0m0.002s
    
    Run

`-d:lto` flag makes code much faster.

If you really want to know why, you need to read Nim generated C code and 
assembly code generated by backend C compiler. Nim generates assembly code with 
`--asm` option. But if you use `-d:lto` flag, see: 
<https://internet-of-tomohiro.netlify.app/nim/faq.en.html#nim-compiler-how-to-produce-assembler-codeqmark>

You can get simpler assembly code with `-d:danger` as it remove runtime checks.

<https://godbolt.org> shows assembly code but it is less readable because it 
doesn't tell function name `call` instruction calls and hard to see where jmp 
instructions jump to.

Reply via email to