Extremely narrow optical resonances in cold atoms or single trapped ions can be measured with high resolution. A laser locked to such a narrow optical resonance could serve as a highly stable oscillator for an all-optical atomic clock. However, until recently there was no reliable clockwork mechanism that could count optical frequencies of hundreds of terahertz. Techniques using femtosecond-laser frequency combs, developed within the past few years, have solved this problem. The ability to count optical oscillations of more than 1015 cycles per second facilitates high-precision optical spectroscopy, and has led to the construction of an all-optical atomic clock that is expected eventually to outperform today's state-of-the-art caesium clocks.