# Show render time on pages

**URL:** <https://www.ruby-forum.com/t/show-render-time-on-pages/76372>\
**Category:** Rails\
**Created:** [December 26, 2005, 1:42pm UTC](https://www.ruby-forum.com/t/show-render-time-on-pages/76372 "2005-12-26T13:42:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [December 26, 2005, 1:42pm UTC](https://www.ruby-forum.com/t/show-render-time-on-pages/76372/1 "2005-12-26T13:42:24Z")

</div>

hello all!  
is it possible to access the render time variables in the view? i would  
like to show

Completed in 0.09574 (10 reqs/sec) | DB: 0.08729 (91%) | 200 OK  
[[http://localhost/person](http://localhost/person)]

on each page like in the logs.

how can i do this?

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [December 26, 2005, 4:22pm UTC](https://www.ruby-forum.com/t/show-render-time-on-pages/76372/2 "2005-12-26T16:22:04Z")

</div>

Simon S. wrote:

> hello all!  
> is it possible to access the render time variables in the view? i would  
> like to show
> 
> Completed in 0.09574 (10 reqs/sec) | DB: 0.08729 (91%) | 200 OK  
> [[http://localhost/person](http://localhost/person)]
> 
> on each page like in the logs.
> 
> how can i do this?  
> If render time can only access in a controller, Try setting up a message  
> in  
> controller then. Moreover, you can use flash variable to do the job  
> since  
> you want the message to appear every page :),

Tom

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [December 26, 2005, 5:25pm UTC](https://www.ruby-forum.com/t/show-render-time-on-pages/76372/3 "2005-12-26T17:25:09Z")

</div>

Anocha Yimsiriwattana wrote:

> If render time can only access in a controller, Try setting up a message in  
> controller then.

I don’t know if it is accessible in the controller. I don’t know where  
to look for them…

> Moreover, you can use flash variable to do the job since  
> you want the message to appear every page :),

Oh well. Once I get to them, displaying them will be the last of th  
problems 🙂

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [December 26, 2005, 5:43pm UTC](https://www.ruby-forum.com/t/show-render-time-on-pages/76372/4 "2005-12-26T17:43:18Z")

</div>

Simon S. wrote:

> Oh well. Once I get to them, displaying them will be the last of th  
> problems 🙂  
> Arr … I thought you know how to access it in controller, my bad. I was  
> going to ask you how to do that too 😛

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [December 26, 2005, 8:56pm UTC](https://www.ruby-forum.com/t/show-render-time-on-pages/76372/5 "2005-12-26T20:56:25Z")

</div>

By definition, if you can see the page, you got a 200 response so that’s  
very possibly not what you want. If render time is what you’re after, an  
approximate way to capture that is:

RAILS\_ROOT/app/views/layouts/application.rb

\<%= @content\_for\_layout %\>  
\<%= sprintf(’%f’, (Time.now.usec - @start\_time.usec).to\_f / 1000000) %\>

RAILS\_ROOT/app/views/layouts/controller\_to\_time.rb

```
def initialize
	@start_time = Time.now;
	super
end

```

Naturally, a better way to do this would be to actually _change_  
ApplicationController on the fly so this initialize code happens all the  
time.

Regarding DB, that’s kind of up to you, but a similar technique in  
ActiveRecord would work.

By the way, Windows does not render the time to anywhere near the amount  
of  
precision \*nix does.

Hope this helps.
