Measuring speed/distance of model train set

A small magnet glued to the underside of the loco, and some Hall effect switches in the track?