Skip to content

Commit d0341f7

Browse files
committed
Update benchmark allocations helper to support min count.
This is useful when we have many groups because each group is a separate class.
1 parent 5b12238 commit d0341f7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

benchmarks/allocations/helper.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'rspec/core'
33
require 'allocation_stats'
44

5-
def benchmark_allocations(burn: 1)
5+
def benchmark_allocations(burn: 1, min_allocations: 0)
66
stats = AllocationStats.new(burn: burn).trace do
77
yield
88
end
@@ -13,5 +13,11 @@ def benchmark_allocations(burn: 1)
1313
[:class_plus]
1414
end
1515

16-
puts stats.allocations(alias_paths: true).group_by(*columns).from_pwd.sort_by_size.to_text
16+
results = stats.allocations(alias_paths: true).group_by(*columns).from_pwd.sort_by_size.to_text
17+
filtered = results.split("\n").select do |line|
18+
count = line[/\s+(\d+)\z/, 1]
19+
count.nil? || Integer(count) >= min_allocations
20+
end.join("\n")
21+
22+
puts filtered
1723
end

0 commit comments

Comments
 (0)