Click here to Skip to main content
13,002,343 members (80,260 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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) = Real = Imaginary
       refreshar = True
       refreshmag = True
    End Sub
End Class

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
Posted 4-May-13 11:39am
Zoltán Zörgő 4-May-13 17:43pm
First of all, I suggest make your tests with a release mode build, and from outside VisualStudio.
Keex0r 4-May-13 17:51pm
Ok I did this, which improved the speed. But it also improved the speed of the built-in class so mine is still way slower.
Pretty good question, I voted 4.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Keex0r 4-May-13 17:56pm
Oh now I feel a little dumb. You are right, it was the difference between Structure<->Class I did not notice. That improved it to nearly completely matching the speed.

Thank you.

Also thanks Zoltan, the reminder of the Built-type was an important one too, and overlooked by me.
CPallini 4-May-13 18:09pm
You are welcome.
Of course, such "complex" (in another sense of the word, non-primitive) types with numeric semantic should be structs, but I cannot really see why it can improve performance dramatically. I guess, it depends on operations typically performed on these types. So, I can only trust OP's observation. My 5.
I don't think you a dump at all, so I up-voted this question; even though for 99% questions on this forum, these days, even the vote of 1 would be too much. I guess the level of dumbness depends on comparison. :-)
CPallini 5-May-13 12:47pm
Allocation performance should be better because they are allocated on the stack, I guess.
By the way: Thank you.
I understand. Passing a reference and mutable operations are faster for reference type, but, as I say, this is specific to operations: for a numeric type, it's all poorly functional, and the type is small..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 4 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100