Quantifying Timing Leaks and Cost Optimisation