In August 2012, I went to San Francisco Airport (SFO) when I was on my way back to New York. Transit time is about 6 hours, which is from midnight to 6 AM.
Immigration checks took me about 45 minutes, from the moment I line up until I take back my luggage. The process is pretty much streamlined so you don’t have to worry much about that. Just remember to declare any sensitive item that you might have (such as food and plants).
A room for travelers to rest. Very clean and comfortable. Somewhat I think this is better than JFK restrooms.
Six hours in deserted airport was too long for me. So I went to the city (about 30 miles away) and spend the whole night there.