(buying comes out slightly ahead assuming you don't move for 25 years, and the renter averages 7.5%/year returns on their investments, and, and, and etc.)
TL;DR buying is probably better if you don't move very often, but there are so many variables that you can't know beforehand -- that you need to be able calculate whether renting vs buying is more profitable -- that it's probably not worth worrying about.
EDIT: The NYT also has a nice visual calculator for this: https://www.nytimes.com/interactive/2014/upshot/buy-rent-cal... You need to know about 21 variables (that can change over time during the lifetime of your mortgage).