Is 'yield return' slower than “old school” return?

后端 未结 5 1507
滥情空心
滥情空心 2020-12-19 10:01

I\'m doing some tests about yield return perfomance, and I found that it is slower than normal return.

I tested value variables (int, double, etc.) and some referenc

5条回答
  •  春和景丽
    2020-12-19 10:34

    Because C# compiler converts iterator blocks (yield return) into state machine. State machine is very expensive in this case.

    You can read more here: http://csharpindepth.com/articles/chapter6/iteratorblockimplementation.aspx

提交回复
热议问题