Theory of mirror benchmarking and demonstration on a quantum computer