optimized period calculation