Refactor to reduce duplicated benchmark/test code.