How can adding code to a loop make it faster?

前端 未结 5 1917
醉梦人生
醉梦人生 2020-12-03 17:13

I have a simple function with an inner loop - it scales the input value, looks up an output value in a lookup table, and copies it to the destination. (ftol_ambient is a tri

5条回答
  •  萌比男神i
    2020-12-03 17:31

    I once had a similar situation. I hoisted some code out of a loop to make it faster, but it got slower. Confusing. Turns out, the average number of times though the loop was less than 1.

    The lesson (which you don't need, obviously) is that a change doesn't make your code faster unless you measure it actually running faster.

提交回复
热议问题