Sha256: 727e3f1c0dcc5a11ffafc32ef33d768102bc1ea991b080f4637e5eb4415b9837

Contents?: true

Size: 890 Bytes

Versions: 62

Compression:

Stored size: 890 Bytes

Contents

# encoding: UTF-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

raise Mysql2::Mysql2Error.new("GC allocation benchmarks only supported on Ruby 1.9!") unless RUBY_VERSION =~ /1\.9/

require 'rubygems'
require 'benchmark'
require 'active_record'

ActiveRecord::Base.default_timezone = :local
ActiveRecord::Base.time_zone_aware_attributes = true

class Mysql2Model < ActiveRecord::Base
  set_table_name :mysql2_test
end

def bench_allocations(feature, iterations = 10, &blk)
  puts "GC overhead for #{feature}"
  Mysql2Model.establish_connection(:adapter => 'mysql2', :database => 'test')
  GC::Profiler.clear
  GC::Profiler.enable
  iterations.times{ blk.call }
  GC::Profiler.report(STDOUT)
  GC::Profiler.disable
end

bench_allocations('coercion') do
  Mysql2Model.all(:limit => 1000).each{ |r|
    r.attributes.keys.each{ |k|
      r.send(k.to_sym)
    }
  }
end

Version data entries

62 entries across 62 versions & 7 rubygems

Version Path
mysql2-0.2.18-x86-mingw32 benchmark/allocations.rb
mysql2-0.2.18 benchmark/allocations.rb
mysql2-0.3.10 benchmark/allocations.rb
mysql2-0.2.17 benchmark/allocations.rb
mysql2-0.2.16 benchmark/allocations.rb
mysql2-0.3.9 benchmark/allocations.rb
mysql2-0.2.16-x86-mswin32-60 benchmark/allocations.rb
mysql2-0.2.16-x86-mingw32 benchmark/allocations.rb
mysql2-0.3.9-x86-mswin32-60 benchmark/allocations.rb
mysql2-0.3.9-x86-mingw32 benchmark/allocations.rb
mysql2-0.2.15-x86-mswin32-60 benchmark/allocations.rb
mysql2-0.3.8 benchmark/allocations.rb
mysql2-0.2.14 benchmark/allocations.rb
mysql2-0.3.7 benchmark/allocations.rb
mysql2-0.2.13 benchmark/allocations.rb
mysql2-0.2.12 benchmark/allocations.rb
mysql2-0.3.6 benchmark/allocations.rb
mysql2-0.2.11 benchmark/allocations.rb
mysql2-0.3.5 benchmark/allocations.rb
mysql2-0.2.10 benchmark/allocations.rb