<div dir="ltr"><div>I've wrote simple Haskell benchmark program, which populated primitive vector from vector package:</div><div><br></div><div>import Data.Vector.Primitive.Mutable as P</div><div><br></div><div>vectorBench :: Benchmark</div><div>vectorBench = bgroup "vector" [ primitive ]</div><div> where</div><div> primitive = bgroup "primitive" [ write1M ]</div><div> where</div><div> write1M = bench "write1M" $ nfIO $ do</div><div> v <- P.unsafeNew 1000000</div><div> void $ for [0..1000000 - 1] $ flip (P.unsafeWrite v) (1 :: Int)</div><div> return ()</div><div><br></div><div>I use `unsafeNew` to skip memory initialization and `unsafeWrite` to skip boundary checks, I guess it's fastest possible way to write something to vector. My result was about 40 ms. </div><div><br></div><div>I wrote similar program in Scala:</div><div><br></div><div>for (_ <- 1 to 5) {</div><div> val start = System.currentTimeMillis()</div><div> val a = new Array[Long](1000000)</div><div> for (i <- 0 until 1000000) {</div><div> a(i) = 1L</div><div> }</div><div> val end = System.currentTimeMillis()</div><div> println(s"${end - start} ms")</div><div>}</div><div><br></div><div>I skip neither boundary checks nor memory initialization, I also used generic array here (suitable for any types of objects, not just for primitive types), so I expected longer run time. But what I got was shocking:</div><div><br></div><div>7 ms</div><div>3 ms</div><div>2 ms</div><div>1 ms</div><div>2 ms</div><div><br></div><div>This program runs 20-40 times faster than Haskell after warm-up. 20-40 times, Carl! Why is Haskell soo slooooow? How can it be?</div><div> <br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span style="font-family:arial;font-size:small">Sincerely, Stanislav Chernichkin.</span><br></div></div>
</div></div>