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.



22
23
24
25
# File 'lib/utopia/middleware/benchmark.rb', line 22

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

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/utopia/middleware/benchmark.rb', line 27

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