Assuming both are 10 cp, you'll get 500 prestige and 50 xp by attacking your magikarp with weedle. It's suboptimal, but still a decent way to gain prestige and xp. It'll take less than ten minutes for you to level the gym pass level 7, for example.
Unfortunately, there's no way for you to remove your magikarp from the gym. You'll have to wait until someone come and knock it out. This is why it's valuable to keep an eye out for more matchup options.
Bubblestrat is the fastest way to power level gyms, and depending on your setup, potentially the most efficient way to powerlevel your trainer as well.