summaryrefslogtreecommitdiff
path: root/ruby_2_2/benchmark/gc
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-14 15:59:18 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-14 15:59:18 +0000
commit72113d58cd2fc62b3f4ef3d2eb6cec37393532a4 (patch)
tree534843caaea28f1171378c1ac5bea0184ed04054 /ruby_2_2/benchmark/gc
parent1a74fa4b04da04bd2bb33103dd3cf431438df38e (diff)
parent02b8978ff10b05304dbb46d73b49a2cf3a87cb92 (diff)
add tag v2_2_9v2_2_9
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v2_2_9@61259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_2_2/benchmark/gc')
-rw-r--r--ruby_2_2/benchmark/gc/aobench.rb1
-rw-r--r--ruby_2_2/benchmark/gc/binary_trees.rb1
-rw-r--r--ruby_2_2/benchmark/gc/gcbench.rb56
-rw-r--r--ruby_2_2/benchmark/gc/hash1.rb11
-rw-r--r--ruby_2_2/benchmark/gc/hash2.rb7
-rw-r--r--ruby_2_2/benchmark/gc/null.rb1
-rw-r--r--ruby_2_2/benchmark/gc/pentomino.rb1
-rw-r--r--ruby_2_2/benchmark/gc/rdoc.rb13
-rw-r--r--ruby_2_2/benchmark/gc/redblack.rb366
-rw-r--r--ruby_2_2/benchmark/gc/ring.rb29
10 files changed, 0 insertions, 486 deletions
diff --git a/ruby_2_2/benchmark/gc/aobench.rb b/ruby_2_2/benchmark/gc/aobench.rb
deleted file mode 100644
index 2eed7abc83..0000000000
--- a/ruby_2_2/benchmark/gc/aobench.rb
+++ /dev/null
@@ -1 +0,0 @@
-require_relative '../bm_app_aobench.rb'
diff --git a/ruby_2_2/benchmark/gc/binary_trees.rb b/ruby_2_2/benchmark/gc/binary_trees.rb
deleted file mode 100644
index af8ea722aa..0000000000
--- a/ruby_2_2/benchmark/gc/binary_trees.rb
+++ /dev/null
@@ -1 +0,0 @@
-require_relative '../bm_so_binary_trees.rb'
diff --git a/ruby_2_2/benchmark/gc/gcbench.rb b/ruby_2_2/benchmark/gc/gcbench.rb
deleted file mode 100644
index 09a404466a..0000000000
--- a/ruby_2_2/benchmark/gc/gcbench.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'benchmark'
-require 'pp'
-require 'optparse'
-
-$list = true
-$gcprof = true
-
-opt = OptionParser.new
-opt.on('-q'){$list = false}
-opt.on('-d'){$gcprof = false}
-opt.parse!(ARGV)
-
-script = File.join(File.dirname(__FILE__), ARGV.shift)
-script += '.rb' unless FileTest.exist?(script)
-raise "#{script} not found" unless FileTest.exist?(script)
-
-puts "Script: #{script}"
-
-if $gcprof
- GC::Profiler.enable
-end
-
-tms = Benchmark.measure{|x|
- load script
-}
-
-gc_time = 0
-
-if $gcprof
- gc_time = GC::Profiler.total_time
- GC::Profiler.report if $list and RUBY_VERSION >= '2.0.0' # before 1.9.3, report() may run infinite loop
- GC::Profiler.disable
-end
-
-pp GC.stat
-
-puts "#{RUBY_DESCRIPTION} #{GC::OPTS.inspect}" if defined?(GC::OPTS)
-
-desc = "#{RUBY_VERSION}#{RUBY_PATCHLEVEL >= 0 ? "p#{RUBY_PATCHLEVEL}" : "dev"}"
-name = File.basename(script, '.rb')
-
-puts
-puts script
-puts Benchmark::CAPTION
-puts tms
-puts "GC total time (sec): #{gc_time}"
-
-# show High-Water Mark on Linux
-if File.exist?('/proc/self/status') && /VmHWM:\s*(\d+.+)/ =~ File.read('/proc/self/status')
- puts
- puts "VmHWM: #{$1.chomp}"
-end
-
-puts
-puts "Summary of #{name} on #{desc}\t#{tms.real}\t#{gc_time}\t#{GC.count}"
-puts " (real time in sec, GC time in sec, GC count)"
diff --git a/ruby_2_2/benchmark/gc/hash1.rb b/ruby_2_2/benchmark/gc/hash1.rb
deleted file mode 100644
index cb030d458d..0000000000
--- a/ruby_2_2/benchmark/gc/hash1.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-value = 0.01
-h = {}
-n = 50_000
-
-1.upto(n){|i|
- h["%020d" % i] = "v-#{i}"
-}
-
-(n * 1_000).times{
- ''
-}
diff --git a/ruby_2_2/benchmark/gc/hash2.rb b/ruby_2_2/benchmark/gc/hash2.rb
deleted file mode 100644
index e8c943fb21..0000000000
--- a/ruby_2_2/benchmark/gc/hash2.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-value = 0.01
-h = {}
-n = 4*(10**6)
-
-1.upto(n){|i|
- h["%020d" % i] = value * i
-}
diff --git a/ruby_2_2/benchmark/gc/null.rb b/ruby_2_2/benchmark/gc/null.rb
deleted file mode 100644
index c05a79f561..0000000000
--- a/ruby_2_2/benchmark/gc/null.rb
+++ /dev/null
@@ -1 +0,0 @@
-# null
diff --git a/ruby_2_2/benchmark/gc/pentomino.rb b/ruby_2_2/benchmark/gc/pentomino.rb
deleted file mode 100644
index 94ba74be89..0000000000
--- a/ruby_2_2/benchmark/gc/pentomino.rb
+++ /dev/null
@@ -1 +0,0 @@
-require_relative '../bm_app_pentomino.rb'
diff --git a/ruby_2_2/benchmark/gc/rdoc.rb b/ruby_2_2/benchmark/gc/rdoc.rb
deleted file mode 100644
index 14c89f5611..0000000000
--- a/ruby_2_2/benchmark/gc/rdoc.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'rdoc/rdoc'
-require 'tmpdir'
-
-srcdir = File.expand_path('../..', __dir__)
-
-Dir.mktmpdir('rdocbench-'){|d|
- dir = File.join(d, 'rdocbench')
- args = %W(--root #{srcdir} --page-dir #{srcdir}/doc --encoding=UTF-8 --no-force-update --all --ri --debug --quiet #{srcdir})
- args << '--op' << dir
-
- r = RDoc::RDoc.new
- r.document args
-}
diff --git a/ruby_2_2/benchmark/gc/redblack.rb b/ruby_2_2/benchmark/gc/redblack.rb
deleted file mode 100644
index c66290140a..0000000000
--- a/ruby_2_2/benchmark/gc/redblack.rb
+++ /dev/null
@@ -1,366 +0,0 @@
-# This benchmark is imported from https://github.com/jruby/rubybench/blob/master/time/bench_red_black.rb
-# License is License is Apache-2
-
-require 'benchmark'
-
-# Algorithm based on "Introduction to Algorithms" by Cormen and others
-class RedBlackTree
- class Node
- attr_accessor :color
- attr_accessor :key
- attr_accessor :left
- attr_accessor :right
- attr_accessor :parent
-
- RED = :red
- BLACK = :black
- COLORS = [RED, BLACK].freeze
-
- def initialize(key, color = RED)
- raise ArgumentError, "Bad value for color parameter" unless COLORS.include?(color)
- @color = color
- @key = key
- @left = @right = @parent = NilNode.instance
- end
-
- def black?
- return color == BLACK
- end
-
- def red?
- return color == RED
- end
- end
-
- class NilNode < Node
- class << self
- private :new
-
- # it's not thread safe
- def instance
- @instance ||= begin
- def instance
- return @instance
- end
-
- new
- end
- end
- end
-
- def initialize
- self.color = BLACK
- self.key = 0
- self.left = nil
- self.right = nil
- self.parent = nil
- end
-
- def nil?
- return true
- end
- end
-
- include Enumerable
-
- attr_accessor :root
- attr_accessor :size
-
- def initialize
- self.root = NilNode.instance
- self.size = 0
- end
-
- def add(key)
- insert(Node.new(key))
- end
-
- def insert(x)
- insert_helper(x)
-
- x.color = Node::RED
- while x != root && x.parent.color == Node::RED
- if x.parent == x.parent.parent.left
- y = x.parent.parent.right
- if !y.nil? && y.color == Node::RED
- x.parent.color = Node::BLACK
- y.color = Node::BLACK
- x.parent.parent.color = Node::RED
- x = x.parent.parent
- else
- if x == x.parent.right
- x = x.parent
- left_rotate(x)
- end
- x.parent.color = Node::BLACK
- x.parent.parent.color = Node::RED
- right_rotate(x.parent.parent)
- end
- else
- y = x.parent.parent.left
- if !y.nil? && y.color == Node::RED
- x.parent.color = Node::BLACK
- y.color = Node::BLACK
- x.parent.parent.color = Node::RED
- x = x.parent.parent
- else
- if x == x.parent.left
- x = x.parent
- right_rotate(x)
- end
- x.parent.color = Node::BLACK
- x.parent.parent.color = Node::RED
- left_rotate(x.parent.parent)
- end
- end
- end
- root.color = Node::BLACK
- end
-
- alias << insert
-
- def delete(z)
- y = (z.left.nil? || z.right.nil?) ? z : successor(z)
- x = y.left.nil? ? y.right : y.left
- x.parent = y.parent
-
- if y.parent.nil?
- self.root = x
- else
- if y == y.parent.left
- y.parent.left = x
- else
- y.parent.right = x
- end
- end
-
- z.key = y.key if y != z
-
- if y.color == Node::BLACK
- delete_fixup(x)
- end
-
- self.size -= 1
- return y
- end
-
- def minimum(x = root)
- while !x.left.nil?
- x = x.left
- end
- return x
- end
-
- def maximum(x = root)
- while !x.right.nil?
- x = x.right
- end
- return x
- end
-
- def successor(x)
- if !x.right.nil?
- return minimum(x.right)
- end
- y = x.parent
- while !y.nil? && x == y.right
- x = y
- y = y.parent
- end
- return y
- end
-
- def predecessor(x)
- if !x.left.nil?
- return maximum(x.left)
- end
- y = x.parent
- while !y.nil? && x == y.left
- x = y
- y = y.parent
- end
- return y
- end
-
- def inorder_walk(x = root)
- x = self.minimum
- while !x.nil?
- yield x.key
- x = successor(x)
- end
- end
-
- alias each inorder_walk
-
- def reverse_inorder_walk(x = root)
- x = self.maximum
- while !x.nil?
- yield x.key
- x = predecessor(x)
- end
- end
-
- alias reverse_each reverse_inorder_walk
-
- def search(key, x = root)
- while !x.nil? && x.key != key
- key < x.key ? x = x.left : x = x.right
- end
- return x
- end
-
- def empty?
- return self.root.nil?
- end
-
- def black_height(x = root)
- height = 0
- while !x.nil?
- x = x.left
- height +=1 if x.nil? || x.black?
- end
- return height
- end
-
-private
-
- def left_rotate(x)
- raise "x.right is nil!" if x.right.nil?
- y = x.right
- x.right = y.left
- y.left.parent = x if !y.left.nil?
- y.parent = x.parent
- if x.parent.nil?
- self.root = y
- else
- if x == x.parent.left
- x.parent.left = y
- else
- x.parent.right = y
- end
- end
- y.left = x
- x.parent = y
- end
-
- def right_rotate(x)
- raise "x.left is nil!" if x.left.nil?
- y = x.left
- x.left = y.right
- y.right.parent = x if !y.right.nil?
- y.parent = x.parent
- if x.parent.nil?
- self.root = y
- else
- if x == x.parent.left
- x.parent.left = y
- else
- x.parent.right = y
- end
- end
- y.right = x
- x.parent = y
- end
-
- def insert_helper(z)
- y = NilNode.instance
- x = root
- while !x.nil?
- y = x
- z.key < x.key ? x = x.left : x = x.right
- end
- z.parent = y
- if y.nil?
- self.root = z
- else
- z.key < y.key ? y.left = z : y.right = z
- end
- self.size += 1
- end
-
- def delete_fixup(x)
- while x != root && x.color == Node::BLACK
- if x == x.parent.left
- w = x.parent.right
- if w.color == Node::RED
- w.color = Node::BLACK
- x.parent.color = Node::RED
- left_rotate(x.parent)
- w = x.parent.right
- end
- if w.left.color == Node::BLACK && w.right.color == Node::BLACK
- w.color = Node::RED
- x = x.parent
- else
- if w.right.color == Node::BLACK
- w.left.color = Node::BLACK
- w.color = Node::RED
- right_rotate(w)
- w = x.parent.right
- end
- w.color = x.parent.color
- x.parent.color = Node::BLACK
- w.right.color = Node::BLACK
- left_rotate(x.parent)
- x = root
- end
- else
- w = x.parent.left
- if w.color == Node::RED
- w.color = Node::BLACK
- x.parent.color = Node::RED
- right_rotate(x.parent)
- w = x.parent.left
- end
- if w.right.color == Node::BLACK && w.left.color == Node::BLACK
- w.color = Node::RED
- x = x.parent
- else
- if w.left.color == Node::BLACK
- w.right.color = Node::BLACK
- w.color = Node::RED
- left_rotate(w)
- w = x.parent.left
- end
- w.color = x.parent.color
- x.parent.color = Node::BLACK
- w.left.color = Node::BLACK
- right_rotate(x.parent)
- x = root
- end
- end
- end
- x.color = Node::BLACK
- end
-end
-
-def rbt_bm
- n = 100_000
- a1 = []; n.times { a1 << rand(999_999) }
- a2 = []; n.times { a2 << rand(999_999) }
-
- start = Time.now
-
- tree = RedBlackTree.new
-
- n.times {|i| tree.add(i) }
- n.times { tree.delete(tree.root) }
-
- tree = RedBlackTree.new
- a1.each {|e| tree.add(e) }
- a2.each {|e| tree.search(e) }
- tree.inorder_walk {|key| key + 1 }
- tree.reverse_inorder_walk {|key| key + 1 }
- n.times { tree.minimum }
- n.times { tree.maximum }
-
- return Time.now - start
-end
-
-N = (ARGV[0] || 10).to_i
-
-N.times do
- # puts rbt_bm.to_f
- rbt_bm.to_f
- # puts "GC.count = #{GC.count}" if GC.respond_to?(:count)
-end
diff --git a/ruby_2_2/benchmark/gc/ring.rb b/ruby_2_2/benchmark/gc/ring.rb
deleted file mode 100644
index be2c7b7250..0000000000
--- a/ruby_2_2/benchmark/gc/ring.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# create many old objects
-
-max = 30_000_000
-
-class Ring
- attr_reader :next_ring
- def initialize n = nil
- @next_ring = n
- end
-
-
- def size
- s = 1
- ring = self
- while ring.next_ring
- s += 1
- ring = ring.next_ring
- end
- s
- end
-end
-
-ring = Ring.new
-
-max.times{
- ring = Ring.new(ring)
-}
-
-# p ring.size