I was debugging some code and realised that a method was taking almost 2 seconds to connect to MySQL. After a bit of digging (Why is constructing PDO connection slow?) I found that it's because I was using 'localhost' instead of '127.0.0.1'. This sped it up significantly. My question is, why? Why does a lookup in my /etc/hosts take so long? I would've thought it was really quick. Also, this optimisation doesn't speed anything up on my work desktop, but definitely worked on my laptop (they're both running Ubuntu 12.04)
Edit: My question is why does it take so long. I understand that the comment in the linked question says that lookups take a long time, but I am asking why.