Browse files

improve test to do proper warmup

  • Loading branch information...
1 parent 0b5bee0 commit 554c6ec3f04fee23b806ca4b8497585440942fd3 @the8472 committed Jan 4, 2013
Showing with 12 additions and 16 deletions.
  1. +12 −16 bench/core/basic_object/ivar_access_bench.rb
View
28 bench/core/basic_object/ivar_access_bench.rb
@@ -2,10 +2,13 @@
SIMPLE_TIMES = 10_000_000
-GROWTH_TIMES = 8_000
+GROWTH_TIMES = 8_000
# prepare dummy objects
-objects = (0..20).map{Class.new.new}
+default_object = Class.new.new
+default_object.instance_variable_set(:@foo,2)
+
+disposable_objects = (0..10).map{Class.new.new}
simple_reader = proc{|o| result = nil;SIMPLE_TIMES.times{ result = o.instance_variable_get(:@foo)};result}
simple_writer = proc{|o| SIMPLE_TIMES.times{o.instance_variable_set(:@foo,1)}}
@@ -17,34 +20,27 @@
end
b.report "single threaded reads x#{SIMPLE_TIMES}" do
- o = objects.pop;
- o.instance_variable_set(:@foo,1)
- simple_reader.call(o)
+ simple_reader.call(default_object)
end
b.report "single threaded writes x#{SIMPLE_TIMES}" do
- o = objects.pop
- simple_writer.call(o)
+ simple_writer.call(default_object)
end
b.report "two reader threads x#{SIMPLE_TIMES}" do
- o = objects.pop;
- o.instance_variable_set(:@foo,1)
-
- t1 = Thread.new{simple_reader.call(o)}
- t2 = Thread.new{simple_reader.call(o)}
+ t1 = Thread.new{simple_reader.call(default_object)}
+ t2 = Thread.new{simple_reader.call(default_object)}
t1.join;t2.join
end
b.report "one reader, one writer x#{SIMPLE_TIMES}" do
- o = objects.pop
- t1 = Thread.new{simple_reader.call(o)}
- t2 = Thread.new{simple_writer.call(o)}
+ t1 = Thread.new{simple_reader.call(default_object)}
+ t2 = Thread.new{simple_writer.call(default_object)}
t1.join;t2.join
end
b.report "single threaded growth x#{GROWTH_TIMES}" do
- o = objects.pop
+ o = disposable_objects.pop
(0..GROWTH_TIMES).each{|i| o.instance_variable_set(:"@bar_#{i}",1)}
end

0 comments on commit 554c6ec

Please sign in to comment.