Mercurial > hg > Members > toma > Jungle-haskell
changeset 22:309e3474ae29
add ParWrite2
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 24 Jan 2014 10:55:47 +0900 |
parents | 451bf8dcdc9c |
children | 7f471687756c |
files | test/ParWrite.hs test/ParWrite2.hs |
diffstat | 2 files changed, 66 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/test/ParWrite.hs Fri Jan 24 09:50:27 2014 +0900 +++ b/test/ParWrite.hs Fri Jan 24 10:55:47 2014 +0900 @@ -29,8 +29,9 @@ writeCount = 100000 main = do - jungle <- createTree createJungle treeId - jungle <- createTree jungle treeId2 + jungle <- createJungle + createTree jungle treeId + createTree jungle treeId2 node <- getRootNode jungle treeId node2 <- getRootNode jungle treeId2 @@ -72,13 +73,13 @@ -- utils from ParRead -testTree node h = foldl' (add h) node (concatMap permutations . subsequences $ [0..h]) +testTree node h = foldl' (add (h-1)) node (concatMap permutations . subsequences $ [1..h]) where - add w node h = addc node h w + add x node h = addc x node h -addc node h w = foldl' (add h) node [0..w] - where - add h node pos = addNewChildAt node h pos +-- x回addNewChildAtする +addc 0 node h = addNewChildAt node h +addc x node h = addNewChildAt (addc (x-1) node h) h printTimeSince t0 = do t1 <- getCurrentTime
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/ParWrite2.hs Fri Jan 24 10:55:47 2014 +0900 @@ -0,0 +1,58 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Control.Parallel +import Control.Parallel.Strategies +import Text.Printf +import Jungle +import Data.Maybe +import Data.List +import Data.Time.Clock +import qualified Data.ByteString.Lazy.Char8 as B +import Control.Exception +import System.Environment +import System.IO.Unsafe + +treeDepth = 5 + +main = do + jungle <- createJungle + createTree jungle "test_tree" + node <- getRootNode jungle "test_tree" + let + x = testTree node treeDepth + size_x = size x + putStrLn $ show $ size_x + updateRootNode jungle "test_tree" x + t0 <- getCurrentTime + printTimeSince t0 + let result = map (func jungle) [1..1000] `using` parList rseq + print (length (filter (== size_x) result)) + printTimeSince t0 + + +func jungle num = unsafePerformIO $ do + createTree jungle name + node <- getRootNode jungle name + let + x = testTree node treeDepth + updateRootNode jungle name x + return (size x) + where + name = show num + + +-- ある程度の大きさの木を作れる +-- size $ testTree y 2 = 10 +-- size $ testTree y 6 = 11742 +-- size $ testTree y 8 = 876808 +testTree node h = foldl' (add (h-1)) node (concatMap permutations . subsequences $ [1..h]) + where + add x node h = addc x node h + +-- x回addNewChildAtする +addc 0 node h = addNewChildAt node h +addc x node h = addNewChildAt (addc (x-1) node h) h + +printTimeSince t0 = do + t1 <- getCurrentTime + printf "time: %.2fs\n" (realToFrac (diffUTCTime t1 t0) :: Double)