Cache stats and optimization

Time stats with exporting to json added.
Running time optimizations.