1. Use for loop instead of the Foreach loop to optimize the speed
It is found that the average execution time of the for cycle is about half the implementation time of the Foreach cycle.