Gross domestic product in the three months through June rose 5.12% from a year ago, beating expectations of a slowdown to 4.8% growth.