Get size of each installed formula in homebrew?

homebrew, macos

Solution

brew list --formula | xargs -n1 -P8 -I {} \
    sh -c "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | \
    sort -h -r -k2 - | column -t

It display brews like below in sorted form (by size):

Problem

I would like to find the size of my installed brew packages so I can see how much space each is taking up. How do I go about doing this from the terminal? Note: some of the answers below also include brew cask packages which is also very helpful to this answer.

Original source