File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ require 'benchmark'
2+ require 'cases/sqlserver_helper'
3+ require 'models/topic'
4+ require 'models/reply'
5+
6+ raise "GC allocation benchmarks only supported on Ruby 1.9!" unless RUBY_VERSION >= '1.9'
7+
8+ class GcProfileCase < ActiveRecord ::TestCase
9+
10+ fixtures :topics
11+
12+ def setup
13+ create_mass_topics unless @created_mass_topics
14+ @connection = ActiveRecord ::Base . connection
15+ @select_statement = "SELECT [topics].* FROM [topics]"
16+ end
17+
18+ def test_coercion
19+ bench_allocations ( 'coercion' ) do
20+ Topic . all ( :limit => 100 ) . each do |t |
21+ t . attributes . keys . each do |k |
22+ t . send ( k . to_sym )
23+ end
24+ end
25+ end
26+ end
27+
28+ def test_select
29+ bench_allocations ( 'select' ) do
30+ @connection . send :select , @select_statement
31+ end
32+ end
33+
34+ def test_select_one
35+ bench_allocations ( 'select_one' ) do
36+ 100 . times { @connection . select_one ( @select_statement ) }
37+ end
38+ end
39+
40+
41+ protected
42+
43+ def create_mass_topics
44+ GC ::Profiler . clear
45+ GC ::Profiler . disable
46+ all_topics = Topic . all
47+ 100 . times { all_topics . each { |t | Topic . create! t . attributes } }
48+ @created_mass_topics = true
49+ GC . start
50+ GC ::Profiler . enable
51+ GC ::Profiler . clear
52+ end
53+
54+ def bench_allocations ( feature , iterations = 10 , &blk )
55+ puts "\n GC overhead for #{ feature } "
56+ GC ::Profiler . clear
57+ GC ::Profiler . enable
58+ iterations . times { blk . call }
59+ GC ::Profiler . report ( STDOUT )
60+ GC ::Profiler . disable
61+ end
62+
63+ end
64+
65+
66+
67+
68+
You can’t perform that action at this time.
0 commit comments