Ten to fifteen seconds for shaking and around thirty for stirring are the figures usually given. They are reasonable and they are not the whole answer, since the conditions vary considerably.
Why counting is unreliable
Four variables change how fast a drink chills and dilutes.
Ice temperature. Ice straight from a freezer at minus eighteen degrees behaves quite differently from ice that has been sitting out and is already wet and at zero.
Ice size and quantity. Small cubes and a full vessel both accelerate the process.
Ingredient temperature. Cold ingredients need less work.
Ambient temperature and how vigorously you are working.
A count that produces a perfect drink in January may under-dilute in August with the same recipe.
The physical signals
Frost is the most reliable. When the outside of the shaker or mixing glass frosts evenly and becomes uncomfortable to hold, the drink has reached temperature.
That happens because the vessel has dropped below the dew point, which is a direct indication of the liquid's temperature rather than a proxy for it.
For shaking, the sound changes as the ice breaks down slightly, becoming less of a rattle and more of a slosh.
For stirring, the ice begins to move more freely as it melts and the liquid volume increases.
Target figures
Shaking: ten to fifteen seconds of genuine effort. Twelve is a reasonable default.
Stirring: twenty five to forty seconds depending on ice and conditions. Thirty is a reasonable default.
Egg white drinks: fifteen seconds of dry shaking without ice first, then ten to twelve with ice.
Anything with a large proportion of fortified wine, such as a wet martini, tolerates slightly longer, since there is more liquid volume and less alcohol to protect.
What under-doing it produces
A drink that is harsh, hot and closed, with the alcohol prominent and the aromatics not yet released.
This is the most commonly misdiagnosed fault in home bartending. The instinct is to add sugar, which produces something sweet and still harsh.
The fix is more time or a few millilitres of water.
What over-doing it produces
A drink that is thin, flat and watery, with the spirit washed out and the balance lost.
Shaking for thirty seconds rather than twelve adds a substantial amount of water without any further benefit, since the drink reached temperature long before.
The fix is next time, since water cannot be removed.
Measuring it yourself
Worth doing once and it takes five minutes.
Measure your ingredients into the shaker and note the total volume. Shake as you normally would, strain into a measuring vessel, and note the new volume.
The difference is your dilution. A shaken drink should gain twenty five to thirty per cent, and a stirred one twenty to twenty five.
Most people who try this find they shake or stir considerably less than they thought.
Practical advice
Use cold, dry ice and plenty of it, which makes the timing more predictable.
Work by feel rather than by count once you have a sense of it.
Taste before straining, which is what every competent bartender does and takes three seconds.
And do not strain and leave a drink standing on the ice while you do something else, since it continues diluting.
A note on very cold ice
Ice straight from a domestic freezer sits at around minus eighteen degrees, well below freezing point.
It needs a few seconds to come up to zero before it begins melting properly, which is why the first moments of shaking or stirring achieve less than the rest.
That is part of why the recommended times are longer than they might seem, and why very cold ice dilutes less overall.
Working in a warm kitchen
Everything happens faster in a warm room, which means shorter times and more careful attention.
Chilling the ingredients and the glassware beforehand compensates, and it is worth doing in summer when the difference is most pronounced.