我的(简单)构造函数似乎很慢 [英] My (simple) constructor seems slow
问题描述
大家好,
我正在编写一个复杂数字的计算类,因为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 inComplex
is not aClass
but aStructure
. Did you try using aStructure
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屋!