It depends on the Pokemon that is switching in, both have their own merits. Stealth Rock hits everything, breaking potential Focus Sashes and Sturdy, while also being able to deal up to 50% on Pokemon 4x weak to Stealth Rock such as Volcarona. Spikes on the other hand can be stacked, and deal more damage depending on how many layers of Spikes you have up. The difference here is that Spikes is not affected by typings, so whatever type you are (bar flying) you will always take the same damage by Spikes. There are some situations where Pokemon avoid hazards altogether, in the case of Magic Guard or Pokemon with Levitate avoid Spikes. It's all completely Pokemon dependent as some Pokemon do not mind hazards while others are completely unviable as a result of hazards.
|