From: David Masover Date: 2009-09-23T10:19:48+09:00 Subject: Re: File.exists? performance On Tuesday 22 September 2009 11:34:59 am Marcelo Barbudas 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 Etzold 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.