As the sun rises, the chirrups, chirps and trills of songbirds sing out a dawn chorus. But what is it that makes birds sing mostly at dawn, rather than midday, and why do they often have another warbling session at dusk?

The daily singing routine of birds is a puzzle. Is dawn the best time to attract a mate, or do birds just wake up feeling chirpy? Scientists at Bristol University have been trying to answer this question by combining a mathematical model of bird behaviour with the results ofhours of watching robins twittering. Now they think they understand the advantages of singing at particular times of day.

John McNamara, Innes Cuthill, Rob Thomas and John Hutchinson developed a model to investigate the trade off for small birds between singing and feeding. They realised that birds sing to attract a mate, but that a bird can't spend all day singing as it needs to eat and store up fat to have the energy to survive.

Equally, the bird doesn't want to spend all day eating, as it may miss out on chatting up a potential partner. Plus, if it becomes too plump, it will be easy prey for a cat.

How does a bird decide when it is going to eat, sing or rest? The Bristol team created a model based on eating, singing and resting to compute the optimum activity for a small bird at any time of day. And, indeed, the model predicted that the best time for a bird to whistle was as the sun was rising.

The reason became obvious when the scientists looked at the model's forecast for a bird's energy reserves throughout the day. Since birds cannot predict exactly how much energy they will need to survive the night, they tend to over-eat before they go to sleep. Most nights are not that cold, so the bird still has reserves of energy at dawn. And what could be better than using the spare energy on a quick burst of song before breakfast?

Another smaller peak in energy reserves happened at dusk, supporting the evidence that birds also like to sing before they go to bed. To test the model in real life, the scientists experimented with the help of wild robins. They set up electronic balances in an area of woodland and trained the robins to weigh themselves by putting a few worms on the scales.

Soon the robins were happily weighing themselves throughout the day, while some strategically placed cameras created a weight-watcher's chart for each bird. The scientists trained their binoculars on the birds and recorded the timings of singing, eating and resting.

Sure enough, the robins tended to have most excess energy at dawn and consequently made quite a cacophony then. On many nights, they also had a little chortle around dusk before settling down for the night.

They also indulged in a little binge eating if the scientists made their food supply less predictable, or when it looked like there was going to be a cold night ahead.

"The uncertainty in the food supply during the day means that birds need to play safe and build up reserves before dusk. Provided they are not unlucky, they thus have exceeded their dusk target levels of reserves and can afford the time and energy to sing," explains McNamara.

So a robin's first priority is to make sure it has enough to eat. If it has any spare time and energy, it tries to attract a mate by singing a song. I wonder if humans work on the same principles? Perhaps wolf-whistling builders have just had too much to eat.