Sha256: 3601926872d10fa44f0fafbb11528b26b9f4783a82e0d700cfab80b03f596b20

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

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 = CompleteBinaryTree.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
#

EOF

ns.each { |n|
  h = CompleteBinaryTree.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]

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
compsci-0.3.3.1 test/bench/complete_tree.rb
compsci-0.3.2.4 test/bench/complete_tree.rb
compsci-0.3.2.3 test/bench/complete_tree.rb
compsci-0.3.2.1 test/bench/complete_tree.rb
compsci-0.3.1.1 test/bench/complete_tree.rb
compsci-0.3.0.1 test/bench/complete_tree.rb
compsci-0.2.0.1 test/bench/complete_tree.rb