Code optimization

后端 未结 3 1621
鱼传尺愫
鱼传尺愫 2021-01-29 16:07

When i\'m trying to optimize my code, I often run into a dilemma:

I have an expression like this:

int x = 5 + y * y;
int z = sqrt(12) + y * y;

3条回答
  •  感情败类
    2021-01-29 16:52

    You don't need a temporary variable:

    int z = y * y;
    int x = z + 5
    z = z + sqrt(12);
    

    but the only way to be sure if this is (a) faster and (b) truly where you should focus your attention, is to use a profiler and benchmark your entire application.

提交回复
热议问题