Forum: Ruby nil? takes much time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Victor S. (Guest)
on 2006-04-28 02:52
(Received via mailing list)
Hello all.

In one my class I've had very simple method:

...
def stored?
  !@db.nil?
end
...

And I've suddenly noticed (due to profile) that nil? Takes a significant
amount of time here.

Redefining the above method like

def stored?
   @db
end

(in if's it works good) speedups the entire program.

I'm a bit surprized :)

Victor.
This topic is locked and can not be replied to.