-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbenchmark.rb
More file actions
43 lines (33 loc) · 910 Bytes
/
benchmark.rb
File metadata and controls
43 lines (33 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# contributed by Jesse Millikan
# Modified by Wesley Moxam
# *reset*
def item_check(left, right)
return 1 if left.nil?
1 + item_check(*left) + item_check(*right)
end
def bottom_up_tree(depth)
return [nil, nil] unless depth > 0
depth -= 1
[bottom_up_tree(depth), bottom_up_tree(depth)]
end
max_depth = 14
min_depth = 4
max_depth = min_depth + 2 if min_depth + 2 > max_depth
stretch_depth = max_depth + 1
require 'harness'
run_benchmark(1) do
stretch_tree = bottom_up_tree(stretch_depth)
stretch_tree = nil
long_lived_tree = bottom_up_tree(max_depth)
min_depth.step(max_depth, 2) do |depth|
iterations = 2**(max_depth - depth + min_depth)
check = 0
for i in 1..iterations
temp_tree = bottom_up_tree(depth)
check += item_check(*temp_tree)
end
end
end