Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions benchmarks/railsbench/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
rng = Random.new(0x1be52551fc152997)
visiting_routes = Array.new(visit_count) { possible_routes.sample(random: rng) }

c_calls = Hash.new { 0 }
c_loops = Hash.new { 0 }

TracePoint.new(:c_call) do |tp|
method_name = "#{tp.defined_class}##{tp.method_id}"
c_calls[method_name] += 1

case tp.method_id
when /(\A|_)each(_|\z)/, /(\A|_)map\!?\z/
c_loops[method_name] += tp.self.size if tp.self.respond_to?(:size)
when 'times'
c_loops[method_name] += Integer(tp.self)
end
end.enable

run_benchmark(10) do
visiting_routes.each do |path|
# The app mutates `env`, so we need to create one every time.
Expand All @@ -31,3 +46,14 @@
end
end
end

puts "Top C loop method iterations:"
c_loops.sort_by(&:last).reverse_each do |method, count|
puts '%8d %s' % [count, method]
end
puts

puts "Top 100 C method calls:"
c_calls.sort_by(&:last).reverse[0...100].each do |method, count|
puts '%8d %s' % [count, method]
end