If you want to avoid any DNS lookups, you should put both entries in your hosts file:
127.0.0.1 www.example.com example.com
Adding example.com
speeds up the first request made to http://example.com
, whereas having just www.example.com
speeds up the subsequent page loads after it's been redirected.
In other words, taking out example.com
only matters if a) you're accessing the site via its non-canonical name and b) you're actually worried about the one-time delay it incurs.
Having said that, it should be mentioned that this is only useful during development though :)