I have written a differential evolution algorithm in cpp and Nim. My cpp version is faster (6-8 times) and I was hoping I could get comparable performance with the Nim implementation. I need a hand.
Nim version: [https://github.com/peheje/nim_genetic/blob/master/DifferentialEvolution/app.nim](https://github.com/peheje/nim_genetic/blob/master/DifferentialEvolution/app.nim) Compiling with nim compile -d:release app.nim cpp version: [https://github.com/peheje/differential_evolution_cpp/blob/master/differential_evolution/main.cpp](https://github.com/peheje/differential_evolution_cpp/blob/master/differential_evolution/main.cpp) Compiling with -Ofast and Link Time optimization: Monolithic in XCode. When I run the Nim profiler it seem something called **system.nim: genericReset** is time consuming, what is this? Entry: 1/6 Calls: 14/52 = 26.92% [sum: 14; 14/52 = 26.92%] system.nim: app 52/52 = 100.00% Entry: 2/6 Calls: 13/52 = 25.00% [sum: 27; 27/52 = 51.92%] system.nim: genericReset 25/52 = 48.08% app.nim: app 52/52 = 100.00% Entry: 3/6 Calls: 12/52 = 23.08% [sum: 39; 39/52 = 75.00%] assign.nim: genericReset 25/52 = 48.08% assign.nim: genericReset 25/52 = 48.08% system.nim: app 52/52 = 100.00% Entry: 4/6 Calls: 5/52 = 9.62% [sum: 44; 44/52 = 84.62%] app.nim: f_rand 5/52 = 9.62% app.nim: app 52/52 = 100.00% Entry: 5/6 Calls: 4/52 = 7.69% [sum: 48; 48/52 = 92.31%] app.nim: i_rand 8/52 = 15.38% app.nim: app 52/52 = 100.00% Entry: 6/6 Calls: 4/52 = 7.69% [sum: 52; 52/52 = 100.00%] app.nim: xor128 4/52 = 7.69% app.nim: i_rand 8/52 = 15.38% app.nim: app 52/52 = 100.00% I have not used the random library. I think it is the strategy to make xoroshift unbiased with the while loop is slowing it ([https://github.com/nim-lang/Nim/blob/2a8d2ad4cde1c942a9dbc44598f65d4acf1e0aa6/lib/pure/random.nim#L77](https://github.com/nim-lang/Nim/blob/2a8d2ad4cde1c942a9dbc44598f65d4acf1e0aa6/lib/pure/random.nim#L77)) and my application don't care much about the bias introduced.
