Performance of expression trees

后端 未结 5 1049
别跟我提以往
别跟我提以往 2020-12-30 23:12

My current understanding is that \'hard coded\' code like this:

public int Add(int x, int y) {return x + y;}

will always perform better tha

5条回答
  •  情话喂你
    2020-12-31 00:04

    Your Add function probably compiles to some function overhead (if not inlined) and a single add instruction. Doesn't get any faster than that.

    Even constructing this expression tree is going to be orders of magnitude slower. Compiling a new function for each invocation is going to be incredibly expensive compared to the direct C# implementation.

    Try compiling the function just once and storing it somewhere.

提交回复
热议问题