Statistics for Cache based Optimization of Stencil Computations - An Algorithmic Approach