For visitors to Florence, it is an unpleasant test of endurance – queuing for up to four hours, in baking heat or pouring rain, for the privilege of entering the famed Uffizi Galleries, the repository of the world’s finest collection of Italian Renaissance art.

But now the museum plans to roll out a new system which will cut waiting times down to just a few minutes.

The initiative comes as the galleries continue to attract ever larger crowds, with numbers rising from two million visitors in 2016 to 2.2 million last year.

The museum is testing out a sophisticated algorithm which takes into account the weather, the time of day, whether it is low season or high season and the number of tour groups in order to calculate the best time for individuals to visit.

Tourists who turn up at the Uffizi will take a ticket from one of seven machines, which will then assign them a visiting time during the day.

It could be an hour or two later, depending on the density of tourist traffic.

In the meantime, tourists can wander off and grab a cappuccino or visit some of Florence’s other attractions, rather than being stuck in an interminable queue.