Cooking them on the stove lets you keep an eye on them and enjoy their fragrance. Grind whole spices for freshness and flavor. Whole spices have four times the shelf life of ground spices because their seed coatings and barks protect their flavors, which aren't released until they are ground or heated. A coffee grinder devoted to spices makes grinding a snap, though you can also grind spices, especially small quantities, in a mortar and pestle. Try toasting spices for an even deeper flavor.
Whole spices work best for toasting because ground spices can burn easily.
Some people like to roast their spices in the oven, but I like the control I get by toasting them on the stove where I can see them. Because spices burn easily, it's important to use a heavy-based pan over gentle heat. Shake the pan or stir the spices with a wooden spoon as they heat. They're ready when they become highly aromatic and turn slightly darker, which usually takes just a couple of minutes, but can take as long as five minutes, depending on the spice, the heat, and the pan. Once toasted, immediately pour the spices out of the pan to stop them from cooking further.