C# generated IL for ++ operator - when and why prefix/postfix notation is faster

前端 未结 3 847
温柔的废话
温柔的废话 2021-02-04 02:41

Since this question is about the increment operator and speed differences with prefix/postfix notation, I will describe the question very carefully lest Eric Lippert discover it

3条回答
  •  长情又很酷
    2021-02-04 03:04

    Interesting results. What I would do is:

    • Rewrite the application to do the whole test twice.
    • Put a message box between the two test runs.
    • Compile for release, no optimizations, and so on.
    • Start the executable outside of the debugger.
    • When the message box comes up, attach the debugger
    • Now inspect the code generated for the two different cases by the jitter.

    And then you'll know whether the jitter is doing a better job with one than the other. The jitter might, for example, be realizing that in one case it can remove array bounds checks, but not realizing that in the other case. I don't know; I'm not an expert on the jitter.

    The reason for all the rigamarole is because the jitter may generate different code when the debugger is attached. If you want to know what it does under normal circumstances then you have to make sure the code gets jitted under normal, non-debugger circumstances.

提交回复
热议问题