How do I work out how many Gems are needed to rush build an upgrade?

The formula is quite complicated. The cost in gems per second decreases the greater the time you wish to rush. I.e. the cost of rushing 1 minute is significantly more per second than the cost of rushing 1 week.

It appears that different formulas apply to different time sectors. These sectors being

  • 1 sec > 1 minute : 0 - 60 seconds
  • 1 minute > 1 hour : 60 - 3,600 seconds
  • 1 hour > 1 Day : 3,600 - 86,400 seconds
  • 1 Day > 1 week : 86,400 - 604,800 seconds

Therefore the cost can not be represented by a gradual curve.

enter image description here

The five different formulas used to calculate the costs involved in each segment are as follows, from 1 second down to 1 week and where x = the number of seconds you wish to rush.

enter image description here

Not exactly the simplest of equations and trying to work out the cost in your head just by looking at the time (if greater than 1 minute) would be extremely difficult... However the formula can be entered into an excel spread sheet and this is a link to a Live Demo of such a spread sheet. There's also a handy calculator on the Clash of Clans Wiki. I hope these are of some use.

All my info was taken from this website. So Thanks to Wolfgang for his insights.