-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplete_tree.rb
59 lines (42 loc) · 1.11 KB
/
complete_tree.rb
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'compsci/complete_tree'
require 'compsci/timer'
require 'compsci/fit'
include CompSci
timing = {}
ns = [10, 100, 1000, 10_000, 100_000]
# Note, CompleteTree is a very thin wrapper around Array, so we are just
# testing ruby's inherent Array performance here.
# Append / push / insert is constant for ruby Arrays.
puts <<EOF
#
# timing CompleteTree(N)#push where N is the size of the tree
#
EOF
ns.each { |n|
h = CompleteTree.new
n.times { h.push rand }
_val, secs = Timer.loop_avg {
h.push rand
}
puts "CompleteTree(%i) push: %0.8f" % [n, secs]
timing[n] = secs
break if secs > 1
}
a, b, r2, fn = Fit.best timing.keys, timing.values
puts "best fit: #{fn} (%0.3f); a = %0.6f, b = %0.6f" % [r2, a, b]
puts <<EOF
#
# timing CompleteTree#push where N is the count of pushes per batch
#
EOF
ns.each { |n|
h = CompleteTree.new
_val, secs = Timer.loop_avg {
n.times { h.push rand }
}
puts "%ix CompleteTree#push: %0.8f" % [n, secs]
timing[n] = secs
break if secs > 1
}
a, b, r2, fn = Fit.best timing.keys, timing.values
puts "best fit: #{fn} (%0.3f); a = %0.6f, b = %0.6f" % [r2, a, b]