Integration tests for benchmark API.

Still need to fix a possible race in time measurements.

Closes #6003