<div dir="ltr"><div><div><div>Hello!<br><br></div>I've performed a few simple tests using Haskell and C++ on primitives.<br></div><div>I've compilled all Haskell programs with -O2 optimizations, and C++ ones with -O3<br></div><div>ghc version - 7.10.2, gcc version : 5.1.1<br></div><div><br></div><div>I'm sending the codes in the zip file.<br></div><div><br></div><b>Problem1</b> -  100 000 000  iterations.<br><br>Time of execution (in seconds):<br><i>Int  pure tail recursion</i>: 6.911011299962411e-2<br><i>Int# pure tail recursion </i>: 4.587398100011342e-2<br></div><i>IORef for loop</i> 1.1533970820000832<br><div><i>IORef 'tail' recursion</i> 1.0696569040001123<br></div><div><i>STRef for loop</i> 1.1545546840006864<br></div><div><i>STRef tail recursion</i> 1.1110019479992843<br></div><div><i>C++ </i>: 2.7e-07<br><br></div><div>The llvm version could be as fast as C++ one in this problem.<br><br></div><div>Buuut... then there's <b>problem 2</b> (using if or case) - 100 000 000 iterations:<br></div><div><i>Int# tail recursion</i> 1.315346227000191<br></div><div><i>IORef for loop</i>: 2.6442542390004746<br></div><div><i>STRef for loop</i>: 2.669217500999366<br></div><div><i>C++</i>: 0.158056<br><br><br></div><div>Here haskell is about 9 times slower than C++.<br><br></div><div><b>Problem 4</b> - executing the same functionality using bit operations - 100 000 000 iterations:<br></div><div><i>Int# tail recursion:</i> 0.12361123500068061<br></div><div><i>C++:</i> 0.131141<br></div><div><br></div><div>So, Haskell here is as fast as C++.<br><br></div><div>My question is: can IORefs and STRefs be optimized ? I would like very much to rely on them, but I would like to achieve great speeds.<br></div><div>Also, is can one achieve good speeds of execution when using cases or ifs ? If not, what is the other way to do it ? Compiler flags, Cmm optimizations - they are all welcome.<br><br></div><div>And the final question - how hard would it be to implement such optimizations in ghc compiler?<br><br></div><div>Regards,<br></div><div>Mateusz Kłoczko<br></div></div>