-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf.rake
More file actions
90 lines (70 loc) · 1.69 KB
/
perf.rake
File metadata and controls
90 lines (70 loc) · 1.69 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'benchmark/ips'
require 'rack/file'
require 'rack/test'
TEST_CNT = (ENV['TEST_CNT'] || 1_000).to_i
ENV["RAILS_ENV"] = ENV['RACK_ENV'] = "production"
'.:lib:test:config'.split(':').each { |x| $: << x }
require 'application'
APP = CodeTriage::Application
APP.initialize!
ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, nil)
rails_app = APP.instance
@app = Rack::MockRequest.new(rails_app)
def call_app
@app.get("/")
end
desc "hits the url TEST_CNT times"
task :test do
Benchmark.bm { |x|
x.report("#{TEST_CNT} requests") {
TEST_CNT.times {
call_app
}
}
}
end
desc "ips"
task :ips do
Benchmark.ips do |x|
x.report("ips") { call_app }
end
end
desc "outputs GC::Profiler.report data while app is called TEST_CNT times"
task :gc do
GC::Profiler.enable
TEST_CNT.times { call_app }
GC::Profiler.report
GC::Profiler.disable
end
desc "outputs allocated object diff after app is called TEST_CNT times"
task :allocated_objects do
call_app
GC.start
GC.disable
start = ObjectSpace.count_objects
TEST_CNT.times { call_app }
finish = ObjectSpace.count_objects
GC.enable
finish.each do |k,v|
p k => (v - start[k]) / TEST_CNT.to_f
end
end
desc "profiles ruby allocation"
task :mem do
call_app
GC.start
first = StringIO.new
second = StringIO.new
MemoryProfiler.report do
call_app
end.pretty_print(first)
puts first.string
sleep 5
GC.start
MemoryProfiler.report do
TEST_CNT.times { call_app }
end.pretty_print(second)
puts second.string
end