Is there a way to count the number of IL instructions executed?

后端 未结 5 489
萌比男神i
萌比男神i 2021-01-06 06:19

I want to do some benchmarking of a C# process, but I don\'t want to use time as my vector - I want to count the number of IL instructions that get executed in a particular

5条回答
  •  情话喂你
    2021-01-06 07:15

    I don't think it's possible to do what you want. This is because the IL is only used during JIT (Just-In-Time) compilation. By the time the method is running the IL has been translated into native machine code. So, while it might be possible to count the number of IL instructions in a given method/type/assembly statically, there's no concept of this at runtime.

    You haven't stated your intention in knowing the number of IL instructions that would be interpreted. Given that there's only a loose correlation between the IL count of a method body and the actual number of machine code instructions, I fail to see what knowing this number would achieve (other than satisfying your curiosity).

提交回复
热议问题