Remember, ammo conservation effects like the Ammo Box and Ammo Reservation Potion work on the Star Cannon.
Base damage wise, you're doing more damage with the Star Cannon : however, the Megashark adds bullets to its damage, and even Musket Balls will put its damage output above the Star Cannon. With things like Crystal Bullets, it's not even close. The main thing you're getting from the Star Cannon is infinite piercing, so you can use it to kill the Destroyer and get the Megashark in the first place.
However, by the time you've got a Megashark, you can use 12 Hallowed Bars to upgrade your Star Cannon into a Super Star Shooter. It then proceeds to do 15 extra damage per shot and shoot one extra projectile on hit, putting it above even Crystal Bullets. Since it doesn't take resources away from a Megashark craft, you can switch with the Megashark at will - using the Megashark in low threat situations, against single targets and to apply ichor/cursed flames to a boss, and the Super Star Shooter against bosses and when you need piercing damage or burst damage.