Click here to Skip to main content
11,796,774 members (79,372 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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 Wink | ;-) ). 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ő at 4-May-13 17:43pm
First of all, I suggest make your tests with a release mode build, and from outside VisualStudio.
Keex0r at 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.
Sergey Alexandrovich Kryukov at 5-May-13 0:57am
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 at 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 at 4-May-13 18:09pm
You are welcome.
Sergey Alexandrovich Kryukov at 5-May-13 0:59am
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. :-)
Sergey Alexandrovich Kryukov at 5-May-13 0:56am
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.
CPallini at 5-May-13 12:47pm
Allocation performance should be better because they are allocated on the stack, I guess.
By the way: Thank you.
Sergey Alexandrovich Kryukov at 5-May-13 14:08pm
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
0 Abhinav S 379
1 OriginalGriff 360
2 Maciej Los 360
3 CPallini 295
4 KrunalRohit 280
0 OriginalGriff 2,032
1 Maciej Los 1,725
2 KrunalRohit 1,310
3 CPallini 1,055
4 ppolymorphe 883

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 4 May 2013
Copyright © CodeProject, 1999-2015
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