Navigation Menu

Skip to content

Commit

Permalink
clean up benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kanwei committed Mar 29, 2009
1 parent 301c092 commit f3f7d4a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 51 deletions.
51 changes: 0 additions & 51 deletions benchmark.rb

This file was deleted.

17 changes: 17 additions & 0 deletions benchmarks/deque.rb
@@ -0,0 +1,17 @@
$: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
require 'algorithms'
include Algorithms

require 'rubygems'
require 'rbench'

RBench.run(2) do
%w(array deque).each { |s| self.send(:column, s.intern) }
deque = Containers::Deque.new
array = []

report "Insertion at end" do
array { 1000000.times { |x| array << x } }
deque { 1000000.times { |x| deque.push_back(x) } }
end
end
36 changes: 36 additions & 0 deletions benchmarks/treemaps.rb
@@ -0,0 +1,36 @@
$: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
require 'algorithms'
include Algorithms

require 'rubygems'
require 'rbench'

RBench.run(10) do
trees = %w(hash rbtree splaytree)
trees.each { |tree| self.send(:column, tree.intern) }

rbtree = Containers::RBTreeMap.new
splaytree = Containers::SplayTreeMap.new
hash = Hash.new

random_array = Array.new(10000) { |i| rand(i) }
num = 1000

report "Insertion" do
rbtree { random_array.each_with_index { |x,index| rbtree[index] = x } }
splaytree { random_array.each_with_index { |x,index| splaytree[index] = x } }
hash { random_array.each_with_index { |x,index| hash[index] = x } }
end

report "has_key?" do
rbtree { num.times { |n| rbtree.has_key?(n) } }
splaytree { num.times { |n| splaytree.has_key?(n) } }
hash { num.times { |n| hash.has_key?(n) } }
end

report "Lookup in sorted order" do
rbtree { rbtree.each { |k, v| k } }
splaytree { splaytree.each { |k, v| k } }
hash { hash.sort.each { |k, v| k } }
end
end

0 comments on commit f3f7d4a

Please sign in to comment.