We've done this before-- this is the conservation of energy, and in order to find the period of the simple harmonic oscillation, we take the time derivative.
This posed a conundrum for researchers working with the laser: How were they to apply the laws of conservation of charge and conservation of energy with two forms of energy output?