Add a test to count the number of allocations made in an API call.

At the moment it's not too bad (73 allocations), but there's room for
improvement.

Change-Id: I0885a73618393a27a161e8cfeb1fe9ffab07514a