# HG changeset patch # User Daichi TOMA # Date 1390528547 -32400 # Node ID 309e3474ae29f15db64a7af36950150950210105 # Parent 451bf8dcdc9c1ac4b7887d3128686b364e7a302e add ParWrite2 diff -r 451bf8dcdc9c -r 309e3474ae29 test/ParWrite.hs --- 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 diff -r 451bf8dcdc9c -r 309e3474ae29 test/ParWrite2.hs --- /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)