1 prototypes ensureNamespace: #benchmark &delegate: True.
3 benchmark define: #TreeNode &slots: {
9 n@(benchmark TreeNode traits) bottomUpTree: i@(Integer traits) depth: d@(Integer traits)
13 [a ::= 2 * i. b ::= a - 1. c ::= d - 1.
14 n new &left: (n bottomUpTree: b depth: c) &right: (n bottomUpTree: a depth: c) &item: i]
15 ifFalse: [n new &left: Nil &right: Nil &item: i]
18 n@(benchmark TreeNode traits) new &left: l &right: r &item: i
20 n clone `>> [left := l. right := r. item := i. ]
23 n@(benchmark TreeNode traits) checkItem
27 ifFalse: [n item + (n left checkItem - n right checkItem)]
30 n@(Integer traits) binaryTrees
33 maxDepth ::= minDepth + 2 max: n.
34 stretchDepth ::= maxDepth + 1.
35 check := (benchmark TreeNode bottomUpTree: 0 depth: stretchDepth) checkItem.
36 longLivedTree ::= benchmark TreeNode bottomUpTree: 0 depth: maxDepth.
37 minDepth upTo: maxDepth by: 2 do:
39 iterations := 1 bitShift: maxDepth - depth + minDepth.
41 1 upTo: iterations do:
43 check += (benchmark TreeNode bottomUpTree: i depth: depth) checkItem.
44 check += (benchmark TreeNode bottomUpTree: (-1 * i) depth: depth) checkItem