我的(简单)构造函数似乎很慢 [英] My (simple) constructor seems slow

查看:84
本文介绍了我的(简单)构造函数似乎很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在编写一个复杂数字的计算类,因为VB.NET内置的复杂 - 自由都存在我无法忍受的缺陷。在性能测试期间,我注意到我的自由行为较慢(这是好的,我不是天才;-))。令我印象深刻的是我的类构造函数慢得多。



在一百万次循环中它比内置的复杂类慢十倍。 br />


我的类构造函数如下所示:

Hello everyone,
I''m writing a class for calculations with complex numbers because the built in Complex-liberary of VB.NET had flaws i couldn''t live with. During performance testing I noticed that my liberary is slower (which is ok, i''m not a genius ;-)). What struck me was that my classes constructor was a lot slower.

On one million cycles it was 10 times slower than the one of the built in complex-class.

My classes constructor looks like this:

Class test
    Private re As Double
    Private im As Double

    Public Sub New(Real As Double, Imaginary As Double)
       Me.re = Real
       Me.im = Imaginary
       refreshar = True
       refreshmag = True
    End Sub
    [...]
End Class





所以真的并没有那么多,并且它仍然需要比内置类更长的时间执行。



是否有人指出可能是什么原因这个?



提前感谢您,如果您需要更多信息,请询问。



Best问候



So there really is not that much going on and still it takes way longer to execute than the one of the built in class.

Does anyone have some pointer on what might be the cause of this?

Thank you in advance, and if you need further infos please ask.

Best regards

推荐答案

我不是专家,但我注意到内置 Complex 不是 Class 但是 Structure 。你自己尝试使用 Structure (对象分配应该更快,但我不知道你是如何进行测试的)? />
在任何情况下,您可能都会查看为两个不同构造函数生成的MSIL。
I''m not an expert but I noticed that built in Complex is not a Class but a Structure. Did you try using a Structure yourself (object allocation should be faster, but I don''t know how you performed the test)?
In any case you may possibly have look at generated MSIL for the two different constructors.


这篇关于我的(简单)构造函数似乎很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆