Created
April 19, 2011 10:27
-
-
Save tibbe/927099 to your computer and use it in GitHub Desktop.
copyArray# benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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