diff --git a/bench/algorithm/binarytrees/2.swift b/bench/algorithm/binarytrees/2.swift new file mode 100644 index 000000000..dc2d05e8d --- /dev/null +++ b/bench/algorithm/binarytrees/2.swift @@ -0,0 +1,64 @@ +import Foundation + +let minDepth = 4 +let maxDepth: Int = { + if CommandLine.argc <= 1 { return 10 } + return max(minDepth + 2, Int(CommandLine.arguments[1]) ?? 10) +}() + +let stretchDepth = maxDepth + 1 +print("stretch tree of depth \(stretchDepth)\t check: \(Tree(depth: stretchDepth).check())") + +let longLivedTree = Tree(depth: maxDepth) +let nResults = (maxDepth - minDepth) / 2 + 1 + +for i in 0.. 0 else { return } + + nodes = Array(repeating: Node(left: Self.none, right: Self.none), count: total) + root = 0 + + for i in 0.. Int { + let span = nodes.span + return _check(index: root, span: span) + } + + private func _check(index: Int, span: Span) -> Int { + if index == Self.none { return 0 } + let node = span[Int(index)] + return 1 + _check(index: node.left, span: span) + + _check(index: node.right, span: span) + } +} diff --git a/bench/bench_swift.yaml b/bench/bench_swift.yaml index 1273c20b7..4fedb7da8 100644 --- a/bench/bench_swift.yaml +++ b/bench/bench_swift.yaml @@ -6,6 +6,7 @@ problems: - name: binarytrees source: - 1.swift + - 2.swift - name: nbody source: - 7.swift @@ -30,7 +31,7 @@ environments: - os: linux compiler: swift version: latest - docker: swift:jammy + docker: swift:6.2.0-slim include: swift include_sub_dir: Sources/app build: swift build --static-swift-stdlib -c release -v -Xswiftc -Ounchecked