File: allocations.rb

package info (click to toggle)
ruby-mysql2 0.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: ansic: 3,459; ruby: 3,334; sh: 226; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 774 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'active_record'

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

class TestModel < ActiveRecord::Base
  self.table_name = 'mysql2_test'
end

def bench_allocations(feature, iterations = 10, batch_size = 1000)
  puts "GC overhead for #{feature}"
  TestModel.establish_connection(adapter: 'mysql2', database: 'test')
  GC::Profiler.clear
  GC::Profiler.enable
  iterations.times { yield batch_size }
  GC::Profiler.report($stdout)
  GC::Profiler.disable
end

bench_allocations('coercion') do |batch_size|
  TestModel.limit(batch_size).to_a.each do |r|
    r.attributes.each_key do |k|
      r.send(k.to_sym)
    end
  end
end