有没有一种方法来计算执行的IL指令数?

编程入门 行业动态 更新时间:2024-10-25 16:20:51
本文介绍了有没有一种方法来计算执行的IL指令数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望做一个C#程序的一些基准测试,但我不希望使用时间作为我的载体 - 我要计算,在一个特定的方法调用得到执行IL指令数。这可能吗?

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 method call. Is this possible?

修改我说的不是方法体的静态分析 - 我指的指令被执行的实际数量 - 所以,如果,例如,该方法主体包括一个循环,计数将增加但许多指令补循环*的次数的循环重复

Edit I don't mean static analysis of a method body - I'm referring to the actual number of instructions that are executed - so if, for example, the method body includes a loop, the count would be increased by however many instructions make up the loop * the number of times the loop is iterated.

推荐答案

我不认为这是可以做到你想要什么。这是因为,IL仅JIT(刚刚在时间)编译期间使用。由当时的方法是运行IL已被翻译成母语机code。因此,虽然有可能算的IL指令数在给定的方法/类型/装配静态,有这样的概念在运行时。

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.

您还没有规定在明知IL指令,这将是PTED跨$ P $数你的意图。假设有一个方法体的IL计数和机器code指令的实际数之间只有松散的关系,我看不出有什么知道这个数字将达到(除了满足你的好奇心)。

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).

更多推荐

有没有一种方法来计算执行的IL指令数?

本文发布于:2023-11-30 21:34:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法来   指令   IL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!