Profiling for making the algorithm faster