mysqlplus/test/gc_benchmark_test.rb

41 lines
855 B
Ruby
Raw Normal View History

require 'mysqlplus'
require 'benchmark'
with_gc = Mysql.real_connect('localhost','root','','mysql')
without_gc = Mysql.real_connect('localhost','root','','mysql')
without_gc.disable_gc = true
2008-10-09 01:01:57 +00:00
$gc_stats = []
def countable_gc?
GC.respond_to? :count
end
def gc_counts( label, scope )
2008-10-09 01:13:40 +00:00
$gc_stats << "Objects #{scope} ( #{label} ) #{GC.count}"
2008-10-09 01:01:57 +00:00
end
def with_gc_counts( label )
gc_counts( label, 'before' ) if countable_gc?
yield
gc_counts( label, 'after' ) if countable_gc?
end
n = 1000
2008-10-09 01:01:57 +00:00
2008-10-09 01:13:40 +00:00
Benchmark.bmbm do |x|
x.report( 'With GC' ) do
2008-10-09 01:01:57 +00:00
with_gc_counts( 'With GC' ) do
n.times{ with_gc.c_async_query( 'SELECT * FROM user' ) }
end
end
GC.start
x.report( 'Without GC' ) do
2008-10-09 01:01:57 +00:00
with_gc_counts( 'Without GC' ) do
n.times{ without_gc.c_async_query( 'SELECT * FROM user' ) }
end
end
2008-10-09 01:01:57 +00:00
end
puts $gc_stats.join( ' | ' )