Class: Utopia::Middleware::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/middleware/benchmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Benchmark

Returns a new instance of Benchmark.



11
12
13
14
# File 'lib/utopia/middleware/benchmark.rb', line 11

def initialize(app, options = {})
	@app = app
	@tag = options[:tag] || "{{benchmark}}"
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/utopia/middleware/benchmark.rb', line 16

def call(env)
	start = Time.now
	response = @app.call(env)
	finish = Time.now

	time = "%0.4f" % (finish - start)
	env['rack.errors'].puts "Benchmark: Request #{env["PATH_INFO"]} took #{time}s"
	
	return response
end