blob: 1e10a0c9629d8a6884d69c2ef5b31bab4995400c (
plain) (
blame)
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
|
$:.unshift(File.dirname(__FILE__) + "/../lib")
require "action_controller"
require 'action_controller/test_process'
Person = Struct.new("Person", :name, :address, :age)
class BenchmarkController < ActionController::Base
def message
render_text "hello world"
end
def list
@people = [ Person.new("David"), Person.new("Mary") ]
render_template "hello: <% for person in @people %>Name: <%= person.name %><% end %>"
end
def form_helper
@person = Person.new "david", "hyacintvej", 24
render_template(
"<% person = Person.new 'Mary', 'hyacintvej', 22 %> " +
"change the name <%= text_field 'person', 'name' %> and <%= text_field 'person', 'address' %> and <%= text_field 'person', 'age' %>"
)
end
end
#ActionController::Base.template_root = File.dirname(__FILE__)
require "benchmark"
RUNS = ARGV[0] ? ARGV[0].to_i : 50
require "profile" if ARGV[1]
runtime = Benchmark.measure {
RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "list" })) }
}
puts "List: #{RUNS / runtime.real}"
runtime = Benchmark.measure {
RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "message" })) }
}
puts "Message: #{RUNS / runtime.real}"
runtime = Benchmark.measure {
RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "form_helper" })) }
}
puts "Form helper: #{RUNS / runtime.real}"
|