Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- datatype tree = Node of int * tree * tree
- | Leaf;
- val kStretchTreeDepth = 24;
- val kLongLivedTreeDepth = 16;
- val kArraySize = 500000;
- val kMinTreeDepth = 4;
- val kMaxTreeDepth = 20;
- fun mktree_bottomup(0) = Leaf
- | mktree_bottomup(n) =
- let val left = mktree_bottomup(n-1)
- and right = mktree_bottomup(n-1)
- in
- Node(1,left,right)
- end;
- fun mktree_topdown 0 = Leaf
- | mktree_topdown n = Node(1,mktree_topdown(n-1), mktree_topdown(n-1));
- fun treeSize(i) =
- let val w = Word.fromInt(1)
- in
- Word.toInt(
- Word.-(Word.<<(w,
- Word.+(Word.fromInt(i),
- w)),
- w))
- end;
- fun numIters(i) = 2* treeSize(kStretchTreeDepth) div treeSize(i);
- fun printDiagnostics() =
- let val freeMemory = 0
- and totalMemory = 0
- in
- let val freeString = String.concat(["free mem available: ", Int.toString(freeMemory), " bytes\n"])
- and totalString = String.concat(["total mem available: ", Int.toString(totalMemory), " bytes\n"])
- in
- print(freeString);
- print(totalString);
- print("\n")
- end
- end;
- fun timeConstrIter(0, _) = ()
- | timeConstrIter(n, depth) =
- let val tempTree = mktree_bottomup(depth)
- in
- timeConstrIter(n-1,depth)
- end;
- fun timeConstruction(depth) =
- let val tStart = Time.now()
- and iNumIters = numIters(depth)
- in
- let val x = timeConstrIter(iNumIters, depth);
- in
- let val tFinish = Time.now();
- in
- print(String.concat(["constructing ", Int.toString(iNumIters), " trees of depth ", Int.toString(depth), "\n"]));
- Time.-(tFinish,tStart)
- end
- end
- end;
- fun mainLoop(depth) =
- if (depth<kMinTreeDepth)
- then ()
- else if (depth > kMaxTreeDepth)
- then ()
- else
- let val longLivedTree = mktree_topdown(kLongLivedTreeDepth)
- and longLivedArray = Array.tabulate(kArraySize,fn i=>if (i<kArraySize div 2) then 1.0/Real.fromInt(i) else 0.0)
- in
- let val t = timeConstruction(depth)
- in
- mainLoop(depth+2)
- end
- end;
Advertisement
Add Comment
Please, Sign In to add comment