From: Victor Shepelev Date: 2006-04-28T11:22:00+09:00 Subject: Re: nil? takes much time > > 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 :) > > > > If you think about it, it's not all that surprising. false and nil > are both immediate values, this means its very quick to check if > something is not false or nil and therefore true. .nil? sends a > message. Sending a message involves [skip] From one side, you are right (and I've must understand all above in myself). What is really unpleasant - is to see how can "infrastructure" code slow down the program. The effect "nil? is slower then direct if" is waitable. What is UNwaitable - that nil? is *noticable* slower (in profile report it was fifth line from top). I hope thing would go better in next ruby's version. Offtopic: BTW, can somebody comment on following questions: 1. How much 1.9 faster than 1.8.4, and how much it stable? 2. When can we wait for Rite? Thanks. Victor.