Skip to content

Commit

Permalink
Add bench of class with many singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Dec 3, 2024
1 parent 0497910 commit c1e9844
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bench/bench_subclasses.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'benchmark/ips'

Custom = Class.new(Object)
# create these once and hold references
many_singletons = 1000.times.map { c = Custom.new; class << c; end; c }

Benchmark.ips do |bm|
[1, 5, 10, 50].each do |count|
bm.report("#{count} thread Numeric.subclasses") do
Expand All @@ -24,5 +28,16 @@
}
}.each(&:join)
end
bm.report("#{count} thread Custom.subclasses with many singletons") do
count.times.map {
Thread.new {
i = 10_000 / count
while i > 0
Custom.subclasses
i-=1
end
}
}.each(&:join)
end
end
end

0 comments on commit c1e9844

Please sign in to comment.