Train for sure.
Tip - Book directly with Renfe, not something like Rail Europe.
I showed up at the station from Valencia to Madrid to catch my flight back to Canada. Was there an hour early at 6 am and would be in Madrid in what should have been enough time to catch my flight. Had issues getting my ticket from the machine with my booking info. There was a long line with the agent, at 6am! Ended up not being able to find the ticket I booked with Rail Europe and by the time I was served I missed the train.
Had to take the next one and ended up 20 mins before my flight from Madrid to Heathrow. They wouldn't let me board. Ended up paying 1000 euros to get from MAD to LHR so I wouldn't miss my Aeroplan flight home. Definitely not a great ending to my vacation