Hi.
How CPU intensive is File.exists? ?
I am thinking of adding theme support in my rails project. I want it to
check if theme image exists and if it doesn’t display a default one.
This would mean a File.exists? for each image_tag call.
Hi.
How CPU intensive is File.exists? ?
I am thinking of adding theme support in my rails project. I want it to
check if theme image exists and if it doesn’t display a default one.
This would mean a File.exists? for each image_tag call.
How CPU intensive is File.exists? ?
I think I should have said I/O.
-------- Original-Nachricht --------
Datum: Wed, 23 Sep 2009 01:34:59 +0900
Von: Marcelo B. [email protected]
An: [email protected]
Betreff: Re: File.exists? performance
How CPU intensive is File.exists? ?
I think I should have said I/O.
–
M.
Dear Marcelo,
you might use profiling with,e.g., ruby-prof.
http://on-ruby.blogspot.com/2006/08/profile-and-ruby-prof.html
Best regards,
Axel
On Tuesday 22 September 2009 11:34:59 am Marcelo B. wrote:
How CPU intensive is File.exists? ?
I think I should have said I/O.
It depends entirely what you’re doing.
But for what you’re talking about, it really can’t be much. Think of it
this
way: How many images are you talking about? If your server has anything
close
to a decent amount of RAM, all of those are going to be cached. You’re
already
doing FAR more than checking if a file exists (basically a stat(2) call,
by my
count it’s going to be at most 52 bytes) than you will if you have to
actually read that image. Worst case, when someone only does a HEAD on
an
image, you’ll be doing two stat calls, so it’ll be about half the usual
speed.
In other words, do what Axel E. suggested – or better yet, don’t
worry
about it. Do it this way, and rethink your architecture (or add some
sort of
caching) if it becomes a problem.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs