Click here to Skip to main content
15,894,740 members
Home / Discussions / C#
   

C#

 
GeneralRe: Primitive types or object types what to prefer Pin
Scott Dorman14-Jan-07 3:38
professionalScott Dorman14-Jan-07 3:38 
GeneralRe: Primitive types or object types what to prefer Pin
Luc Pattyn14-Jan-07 3:55
sitebuilderLuc Pattyn14-Jan-07 3:55 
GeneralRe: Primitive types or object types what to prefer Pin
Scott Dorman14-Jan-07 4:15
professionalScott Dorman14-Jan-07 4:15 
GeneralRe: Primitive types or object types what to prefer Pin
ComCoderCsharp14-Jan-07 4:54
ComCoderCsharp14-Jan-07 4:54 
GeneralRe: Primitive types or object types what to prefer Pin
Scott Dorman14-Jan-07 5:18
professionalScott Dorman14-Jan-07 5:18 
GeneralRe: Primitive types or object types what to prefer Pin
ComCoderCsharp14-Jan-07 5:41
ComCoderCsharp14-Jan-07 5:41 
GeneralRe: Primitive types or object types what to prefer Pin
Scott Dorman14-Jan-07 5:47
professionalScott Dorman14-Jan-07 5:47 
AnswerRe: Primitive types or object types what to prefer Pin
Luc Pattyn14-Jan-07 12:14
sitebuilderLuc Pattyn14-Jan-07 12:14 
Hi,

Having read lots of considerations, some experiments seemed overdue.
So I developed a little test to actually see memory footprint and execution times
for the different complex number approaches.

My test first allocates and initializes 5 million complex numbers stored
- as two float arrays
- as one array of class ComplexClass instances
- as one array of struct ComplexStruct

as expected the numbers were 40MB, 100MB and 40MB respectively,
proving the class instance takes 8B of overhead plus 4B for the pointer (32bit Windows),
the struct has no memory overhead.


Then I continued to measure the time required to square these numbers; I did 5M multiplies,
involving only the first 16K of the numbers in each array (in order to avoid cache misses),
and measured elapsed time.

A release build with Visual 7.1 (.NET 1.1) and Visual 8.0 (.NET 2.0) respectively,
running on a Pentium M at 1.7GHz, performing multiple passes, yielded the following numbers:

		.NET 1.1		.NET 2.0
floats		4110 msec	3970 msec
class		4480 msec	4330 msec
structs		4150 msec	4080 msec
ref structs	4060 msec	3970 msec


The good news here is performance is very much the same in all cases (slightly
over 1M mul/sec); the class is some 10% slower, and the ref struct is the best;
also NET2.0 is marginally faster than NET1.1 here.

Conclusions:
- struct is cheaper than class in RAM and cycles (as expected)
- ref struct is faster than struct (as expected) but only marginally so
- the hard way does not bring anything with respect to ref structs (the positive surprise).

So whenever I would need complex numbers, I would go for structs.
The compiler seems good enough to make the hard way pointless.


Cheers

Luc Pattyn

QuestionC# or C++ and why ? Pin
Software_Specialist13-Jan-07 5:54
Software_Specialist13-Jan-07 5:54 
AnswerRe: C# or C++ and why ? Pin
Ed.Poore13-Jan-07 7:56
Ed.Poore13-Jan-07 7:56 
AnswerRe: C# or C++ and why ? Pin
Colin Angus Mackay13-Jan-07 9:20
Colin Angus Mackay13-Jan-07 9:20 
GeneralRe: C# or C++ and why ? Pin
Software_Specialist13-Jan-07 22:43
Software_Specialist13-Jan-07 22:43 
GeneralRe: C# or C++ and why ? Pin
Nadia Monalisa13-Jan-07 23:45
Nadia Monalisa13-Jan-07 23:45 
GeneralRe: C# or C++ and why ? Pin
Colin Angus Mackay14-Jan-07 3:26
Colin Angus Mackay14-Jan-07 3:26 
QuestionA user-interface question Pin
Zerox MXI13-Jan-07 1:59
Zerox MXI13-Jan-07 1:59 
AnswerRe: A user-interface question Pin
Thomas Stockwell13-Jan-07 5:23
professionalThomas Stockwell13-Jan-07 5:23 
QuestionSomething like chat Pin
CodeItWell13-Jan-07 0:21
CodeItWell13-Jan-07 0:21 
AnswerRe: Something like chat Pin
Thomas Stockwell13-Jan-07 5:24
professionalThomas Stockwell13-Jan-07 5:24 
QuestionQuestion in C# about Interfaces...... Pin
Yanshof13-Jan-07 0:16
Yanshof13-Jan-07 0:16 
AnswerRe: Question in C# about Interfaces...... Pin
Uri Lavi13-Jan-07 5:44
Uri Lavi13-Jan-07 5:44 
GeneralRe: Question in C# about Interfaces...... Pin
Yanshof13-Jan-07 5:54
Yanshof13-Jan-07 5:54 
QuestionWhy does notifyicon disappear when stop a service [modified] Pin
l.m.k12-Jan-07 23:26
l.m.k12-Jan-07 23:26 
AnswerRe: Why does notifyicon disappear when stop a service Pin
Colin Angus Mackay13-Jan-07 9:22
Colin Angus Mackay13-Jan-07 9:22 
GeneralRe: Why does notifyicon disappear when stop a service Pin
l.m.k13-Jan-07 22:12
l.m.k13-Jan-07 22:12 
QuestionHow to access .hlp file in C#.Net [modified] Pin
sjs4u12-Jan-07 23:07
sjs4u12-Jan-07 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.