Skip to content

Commit 470dd56

Browse files
committed
Add bench of class with many singletons
1 parent 0497910 commit 470dd56

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

bench/bench_subclasses.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
require 'benchmark/ips'
22

3+
Custom = Class.new(Object)
4+
# create these once and hold references
5+
SINGLETON_COUNT = 1000
6+
many_singletons = SINGLETON_COUNT.times.map { c = Custom.new; class << c; end; c }
7+
38
Benchmark.ips do |bm|
49
[1, 5, 10, 50].each do |count|
510
bm.report("#{count} thread Numeric.subclasses") do
@@ -24,5 +29,16 @@
2429
}
2530
}.each(&:join)
2631
end
32+
bm.report("#{count} thread Custom.subclasses with #{SINGLETON_COUNT} singletons") do
33+
count.times.map {
34+
Thread.new {
35+
i = 10_000 / count
36+
while i > 0
37+
Custom.subclasses
38+
i-=1
39+
end
40+
}
41+
}.each(&:join)
42+
end
2743
end
2844
end

0 commit comments

Comments
 (0)