Thanks for your respond.
@albanD 's code took 280 ms in my laptop. I cannot find out what out what is the difference between then and which part of my code is responsible to taking too much time of loss backward part.
Could you explain this part? I can not understand this part.

Did you change the code to profile a single iteration?