  We determine the optimal parameters for a simple and efficient scheme of
dispersive readout of a qubit. Depending on the qubit state (ground or
excited), the resonance of a cavity is shifted either to the red or to the blue
side. Qubit state is inferred by detecting the photon number transmitted
through the cavity. It turns out that this kind of detection provides better
measurement fidelity than the detection of the presence or absence of photons
only. We show that radiating the cavity on either of the frequencies it shifts
to results in a suboptimal measurement. The optimal frequency of the probe
photons is determined, as well as the optimal ratio of the shift to the
resonator leakage. It is shown that to maximize the fidelity of a long-lasting
measurement, it is sufficient to use the parameters optimizing the
signal-to-noise ratio in the photon count. One can reach 99% fidelity for a
single-shot measurement in various physical realizations of the scheme.
