What you're thinking now is: Do I have to count that? And, is there a penalty?
The answer depends on whether the ball was already in play.
If the ball is on the teeing ground and you have not yet made a stroke at the ball, then the ball is not yet in play. And accidentally hitting the ball with a practice swing in that situation does not result in a stroke or a penalty. (You can read more explanation on this scenario in the FAQ "Does it count as a stroke if I accidentally bump the ball off the tee?")
However, once you've made a stroke at the ball on the teeing ground, the ball is considered in play until you hole out. Then the question of whether a practice swing that makes contact is a stroke or penalty (or both) is covered under Rule 18, "Ball at Rest Moved."
And here's the ruling: If you accidentally move a ball in play with a practice swing, it's a one-stroke penalty. You must replace the ball to its original position and play it correctly.
Failing to replay the ball from its original position results in a total penalty of two strokes in stroke play or loss of hole in match play.
So be careful with those practice swings!

