-
Notifications
You must be signed in to change notification settings - Fork 22
/
benchmark.rb
48 lines (37 loc) · 1.24 KB
/
benchmark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true
require "bundler/setup"
require "hanami/mailer"
require "benchmark/ips"
require "allocation_stats"
require_relative "./examples/base"
configuration = Hanami::Mailer::Configuration.new do |config|
config.root = "examples/base"
config.delivery_method = :test
end
configuration = Hanami::Mailer.finalize(configuration)
invoice = Invoice.new(1, 23)
user = User.new("Luca", "[email protected]")
mailer = InvoiceMailer.new(configuration: configuration)
Benchmark.ips do |x|
# # Configure the number of seconds used during
# # the warmup phase (default 2) and calculation phase (default 5)
# x.config(time: 5, warmup: 2)
x.report "deliver" do
mailer.deliver(invoice: invoice, user: user)
end
end
stats = AllocationStats.new(burn: 5).trace do
1_000.times do
mailer.deliver(invoice: invoice, user: user)
end
end
total_allocations = stats.allocations.all.size
puts "total allocations: #{total_allocations}"
total_memsize = stats.allocations.bytes.to_a.inject(&:+)
puts "total memsize: #{total_memsize}"
detailed_allocations = stats.allocations(alias_paths: true)
.group_by(:sourcefile, :class_plus)
.sort_by_count
.to_text
puts "allocations by source file and class:"
puts detailed_allocations