Skip to content

Instantly share code, notes, and snippets.

@tibbe
Created April 19, 2011 10:27
Show Gist options
  • Save tibbe/927099 to your computer and use it in GitHub Desktop.
Save tibbe/927099 to your computer and use it in GitHub Desktop.
copyArray# benchmark
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Main (main) where
import Data.Time.Clock
import GHC.Exts
import GHC.IO
import GHC.Prim
import GHC.ST
bench = stToIO $ ST $ \ s ->
case newArray# 32# 0 s of
(# s2, marr #) -> case newArray# 32# 0 s2 of
(# s3, marr2 #) -> case unsafeFreezeArray# marr2 s3 of
(# s4, arr #) -> case copyArray# arr 0# marr 0# 32# s4 of
s5 -> (# s5, () #)
main = do start <- getCurrentTime
go iters
end <- getCurrentTime
print $ (diffUTCTime end start) / fromIntegral iters
where
iters = 1000000 :: Int
go 0 = return ()
go n = bench >> go (n-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment