Compressed sensing leverages the sparsity of signals to reduce the amount of measurements required for its reconstruction. The Shack-Hartmann wavefront sensor meanwhile is a flexible sensor where its sensitivity and dynamic range can be adjusted based on applications. An investigation is done by using compressed sensing in surface measurements with the Shack-Hartmann wavefront sensor. The results show that compressed sensing paired with the Shack-Hartmann wavefront sensor can reliably measure surfaces accurately. The performance of compressed sensing is compared with those of the iterative modal-based wavefront reconstruction and Fourier demodulation of Shack-Hartmann spot images. Compressed sensing performs comparably to the modal based iterative wavefront reconstruction in both simulation and experiment while performing better than the Fourier demodulation in simulation.