Testing speed is really hard. I recommend some thing like 
(benchy)[<https://github.com/treeform/benchy>] rather then `time` utility.

Also a super smart compiler can figure out that you are doing nothing and 
optimize your program out. What you are really testing is not what code is 
faster but how smart your compiler is. How far does your compiler go before it 
bails. Ultimately I think its a bad test. In this case you are just testing the 
underlaying C compiler, not even Nim.

Never the less I did paste your program into the compiler explorer: 
<https://godbolt.org/> . I even diffed the two version and they do produce 
different code but nothing major jumps out to me.

But when I try it on windows I get TotalSeconds : 21.0486674

But the one that does more work is twice as fast: TotalSeconds : 10.8038881

My only thought is that extra `discard reverse()` gives the compiler a hint 
that reverse() can be optimized out? Then it optimizes some but not all 
reverse() calls? But on the other hand that is not true and 
<https://godbolt.org/> shows way more code for the faster case...

I would say its a mystery, but not one I want to continue... 

Reply via email to