Click here to Skip to main content
Rate this: bad
good
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)
            Me.re = Real
            Me.im = 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 12:39pm
Keex0r456
Comments
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.
—SA

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
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. :-)
—SA
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.
—SA
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..
—SA

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 325
2 Richard MacCutchan 265
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 4 May 2013
Copyright © CodeProject, 1999-2014
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