With a critical attack, the axe would deal more damage (up to 8 hearts, depending on which type of axe, whith no enchantments). The axe also stuns shields, whereas the sword doesn't.
In Java edition, the axe has more reload time, and the sword is quicker.
In bedrock edition, attack speed is nonexistent,
So, they are both good in different ways