From a9fea270f57544ce5afa6dc9eb2019dea17c7f48 Mon Sep 17 00:00:00 2001 From: Lourens Naude Date: Thu, 9 Oct 2008 02:01:57 +0100 Subject: [PATCH] Better GC stats --- test/gc_benchmark.rb | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/test/gc_benchmark.rb b/test/gc_benchmark.rb index a2c859f..0f3b397 100644 --- a/test/gc_benchmark.rb +++ b/test/gc_benchmark.rb @@ -6,13 +6,36 @@ with_gc = Mysql.real_connect('localhost','root','','mysql') without_gc = Mysql.real_connect('localhost','root','','mysql') without_gc.disable_gc = true +$gc_stats = [] + +def countable_gc? + GC.respond_to? :count +end + +def gc_counts( label, scope ) + $gc_stats << "GC #{scope} ( #{label} ) #{GC.count}" +end + +def with_gc_counts( label ) + gc_counts( label, 'before' ) if countable_gc? + yield + gc_counts( label, 'after' ) if countable_gc? +end + n = 1000 + Benchmark.bm do |x| x.report( 'With GC' ) do - n.times{ with_gc.c_async_query( 'SELECT * FROM user' ) } + 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 - n.times{ without_gc.c_async_query( 'SELECT * FROM user' ) } + with_gc_counts( 'Without GC' ) do + n.times{ without_gc.c_async_query( 'SELECT * FROM user' ) } + end end -end \ No newline at end of file +end + +puts $gc_stats.join( ' | ' ) \ No newline at end of file