PowerShell:.NET 方法调用的性能
是否可以通过早期绑定从 PowerShell 调用 .NET 方法?
我有一个管道脚本,它在 process {...}
中调用单个 .NET 方法。 PowerShell 通过反射调用此方法,目前 Invoke
(不是方法本身,只是反射调用)占用了总执行时间的 70%。
方法总是相同的,所以我宁愿要求 PowerShell 根本不要使用反射。
Is it possible to call a .NET method from PowerShell with early binding?
I have a pipeline script which calls a single .NET method in process {...}
. PowerShell calls this method via reflection, and right now Invoke
(not the method itself, just reflection call) takes 70% of total execution time.
The method is always the same, so I would prefer to ask PowerShell not to use reflection at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信在 PowerShell 中早期绑定的唯一方法调用类型,或者至少在动态语言中尽可能早期绑定的方法调用类型是以下
我不太确定#2。 我相信他们仍然必须使用反射来获取底层方法。
CmdLets 可能是更好的选择。 在这种情况下,实际的调用会提前绑定,但参数仍然必须经过转换过程。 尝试将您的方法调用移至 CmdLet 中,看看这是否对您有帮助。
I believe the only types of method call that is early bound in PowerShell, or at least as early bound as is possible in a dynamic language, are the following
I'm not as sure about #2. I believe they still have to use reflection to get at the underlying method.
CmdLets are likely the better choice here. In that case the actual call is bound early, but the parameters still must undergo a conversion process. Try moving your method call into a CmdLet and seeing if that helps you out.