Caffeine is a morning highlight for the sleep deprived. But to be effective at work you need the right amount, at the right time.

Now US Army scientists have developed an algorithm, called 2B-Alert Web 2.0, which automatically optimises caffeine doses (both timing and amount) to achieve peak alertness when you need it.

This tool suggests solutions that either required 40 per cent less caffeine or enhanced alertness by an additional 40 per cent — for multiple sleep-deprivation and shift-work scenarios — when compared with US Army guidelines.

It’s not the most user friendly thing in the world, but the algorithm is freely available here you want to have a go.

US Army scientist and lead investigator Jaques Reifman says the tool has practical applications that extend beyond the realms of the military and the research lab.

“For example, if you pull an all-nighter, need to be at peak alertness between, say, 9am and 5pm, and desire to consume as little caffeine as possible, when and how much caffeine should you consume?” he said.

“This is the type of question 2B-Alert was designed to answer.”