On your mark. Get set. Please swipe again.

Riding the New York City Marathon on the city’s mass-transit system was almost as grueling as running it.

It took seven buses and three subway trains to trek through five boroughs along roughly the same 26.2-mile route some 40,000 runners will follow this Sunday.

My race began on the S53 bus in Staten Island, and like the start of the actual marathon, there was little space to breathe.

I had to duck errant elbows and fists, and thanks to one of my fellow riders, I was overcome by the odor of a thousand people sweating.

We hit the starting line at the base of the Verrazano Bridge at exactly 10 a.m.

I mapped out my route, which I dubbed the “Rosie Ruiz run,” using the MTA’s online Trip Planner.

If I made every single connection, I could complete the marathon in three hours, 45 minutes – a respectable finish an hour quicker than my running time last year.

But having ridden the city’s subways and buses all my life, and having written about them for the past two years, I knew, as every runner does, to be prepared for the unexpected on race day.

The weather cooperated until the end of the race; it was a comfy 55 degrees before it started to rain toward the finish line.

Both times I ran the actual race, it was in the mid-60s with no sign of rain to be found.

I got off the S53 on 86th Street and Fourth Avenue in Bay Ridge at 10:09, and at this point, we are on a world-record 3.3-minute- mile pace.

On the R and G trains, I finished two chapters of “War and Peace,” which seemed like appropriate reading material for this adventure, and I reached the halfway mark in Long Island City at 11:15, which put me on track for an elite amateur finish of two hours, 30 minutes.

But I knew from having run the race twice before that this is where the real marathon begins.

Cyclists and pedestrians zipped by us on the jammed 59th Street Bridge.

Then on the M15 bus on First Avenue, we were held up for 47 minutes by a bus driver who did not think marathoning and flash photography were permitted on the transit system.

She insisted on calling her supervisor and held the entire bus hostage while we waited for him to arrive to clear things up.

Instead of getting cheered every step of the way as in the real marathon, now I got yelled at by a pack of elderly women bus passengers who questioned the value and purpose of my enterprise in language unfit for a family paper.

I rounded the stretch up to The Bronx and then back to Manhattan.

The bus driver, having learned of my adventure over the transit radio, stopped me as I swiped my MetroCard.

“So how’s your time going?” she said. “I will do my best to help.”

I told her I was exhausted, desperately needed a bathroom, and was beginning to doubt I would make it.

“Don’t worry, you’re going to make it,” a passenger on the M1 told me.

I crossed the finish line in Central Park in four hours, 57 minutes – two minutes slower than I ran the race in 2006.

Of that time, I spent three hours, 15 minutes riding buses and subways and another one hour, 42 minutes waiting for them.

Along the route that took me on seven buses and three subways, I swiped my MetroCard 10 times.

Nevertheless, I took out my MetroCard once more and felt grateful to live in a city where such feats are even possible.

jeremy.olshan@nypost.com