.NET Performance comparison

.NET Performance comparison

Post by jackmoro » Wed, 28 Mar 2007 23:49:41



Hi All,
I am looking for some interesting article about performance comparison
between .net and c++, possibly provided with benchmarks.
I have searched the web but i've had very few luck,seems like there is
very little information about this issue.
Can you tell me anything about this argoument?
Is it true that c# and vb.net have the same performance? MS says so,
but i've read somewhere that it is not always true, particularly
regarding the i/o and filesystem management, where c# was supposed to
be faster.
I am particularly interested in performance rearding usage and
manipulation of strings, array, hastables, i/0, filesystem directory
handling.I am not interested in UI, graphical applications and other
stuff like this, because my applications is a batch task, it will run
in background on a server as a windows service.

Thanks in advance
Antonello

 
 
 

.NET Performance comparison

Post by hard.. » Thu, 29 Mar 2007 03:53:48


I am not really sure about this. But considering C# and VB.NET are
both running on top of CLR which means they *might be* have the same
MSIL, their performance should be the same.

As for .NET vs C++, I somehow always assume C++ will fare better
than .NET since it is compiled into native machine language
whereas .NET is compiled into MSIL which later run on top of CLR.

Please somebody correct me if I'm wrong :)

Regards,
Hardono Arifanto
-----------------------
http://sodeve.net


Quote:> Hi All,
> I am looking for some interesting article about performance comparison
> between .net and c++, possibly provided with benchmarks.
> I have searched the web but i've had very few luck,seems like there is
> very little information about this issue.
> Can you tell me anything about this argoument?
> Is it true that c# and vb.net have the same performance? MS says so,
> but i've read somewhere that it is not always true, particularly
> regarding the i/o and filesystem management, where c# was supposed to
> be faster.
> I am particularly interested in performance rearding usage and
> manipulation of strings, array, hastables, i/0, filesystem directory
> handling.I am not interested in UI, graphical applications and other
> stuff like this, because my applications is a batch task, it will run
> in background on a server as a windows service.

> Thanks in advance
> Antonello


 
 
 

.NET Performance comparison

Post by carion » Thu, 29 Mar 2007 05:54:31


At least with 1.1 the c++ compiler generated better performing IL.

Is the OP talking about managed or unmanaged c++?


> I am not really sure about this. But considering C# and VB.NET are
> both running on top of CLR which means they *might be* have the same
> MSIL, their performance should be the same.

> As for .NET vs C++, I somehow always assume C++ will fare better
> than .NET since it is compiled into native machine language
> whereas .NET is compiled into MSIL which later run on top of CLR.

> Please somebody correct me if I'm wrong :)

> Regards,
> Hardono Arifanto
> -----------------------http://sodeve.net


> > Hi All,
> > I am looking for some interesting article about performance comparison
> > between .net and c++, possibly provided with benchmarks.
> > I have searched the web but i've had very few luck,seems like there is
> > very little information about this issue.
> > Can you tell me anything about this argoument?
> > Is it true that c# and vb.net have the same performance? MS says so,
> > but i've read somewhere that it is not always true, particularly
> > regarding the i/o and filesystem management, where c# was supposed to
> > be faster.
> > I am particularly interested in performance rearding usage and
> > manipulation of strings, array, hastables, i/0, filesystem directory
> > handling.I am not interested in UI, graphical applications and other
> > stuff like this, because my applications is a batch task, it will run
> > in background on a server as a windows service.

> > Thanks in advance
> > Antonello- Hide quoted text -

> - Show quoted text -

 
 
 

.NET Performance comparison

Post by vwd-cms.co » Thu, 29 Mar 2007 12:51:49


I will add my 2 cents... ;)

I have been coding with C# for quite some time now and I have written
applications as windows services as well as web sites that execute
components that generate code, perform large i/o operations, and
really hammer on the database. I have never had any performance
problems with .NET and C#, actually I am sometimes astonished how
quickly the code executes.

In my opinion, performance when dealing with i/o, arrays, and string
manipulation is far more dependant upon how you write your code, not
what language or environment you are coding in. If you are trying to
build extremely high performance components then you need to keep this
in mind at all times as you are writing the code, here are some things
to consider as you develop your system:

1. Perform the simplest and cheapest (in terms of i/o, memory, cpu
cycles) conditional operations first and by taking advantage of "short-
circuit evaluation" you can avoid executing the more expensive
operations if the cheap ones pass or fail, whatever the case may be.

2. Pass objects or large arrays using the "ref" keyword - this will
prevent .NET from making a copy of the object when it is passed to
another method.

3. Use System.Text.StringBuider instead of System.String / string and
do not do any concatenation, always use the append method of the
StringBuilder. So, instead of doing:
            sb.Append(someData + "\r\n");
you should do:
            sb.Append(someData);
            sb.Append("\r\n");

4. Put strings that you use over and over again in loops (such as the
"\r\n" string above) into constants. You can also put string templates
into constants and then use the string.Format() method to fill in the
template like this:

          const string template = "this is a template string for
'{0}', it will get filled in later...";

          sb.Append(string.Format(template, ".net performance info"));

5. Avoid throwing exceptions as they are very expensive and will kill
the performance of your application. Write your code to meticulously
check the validity of everything before attempting an operation. An
example of this is to always check for null or zero-length strings,
using string.IsNullOrEmpty(), before using the string. Another example
is to use Directory.Exists() and File.Exists() before accessing and
folders or files. Your code will get lengthy and you will appear to be
very uptight, lol, but you will not throw exceptions and that will
speed things up.

That's all I have time for right now, good luck with your coding...

Jeff

 
 
 

.NET Performance comparison

Post by Jamie Frase » Thu, 29 Mar 2007 21:05:37


Im presuming the OP was referring to unmanaged C++

I've been using .NET for several years, and I've never had any
performance issues. That includes projects doing near real time
reconstruction of depth maps from stereo images, performing large data
transformations (hundreds of GB and millions of rows). In fact, the 2
things I've found to be performance limiters are 1) the speed of the
hard disks in my machines and 2) my own optimisations!

-Jamie


> At least with 1.1 the c++ compiler generated better performing IL.

> Is the OP talking about managed or unmanaged c++?


> > I am not really sure about this. But considering C# and VB.NET are
> > both running on top of CLR which means they *might be* have the same
> > MSIL, their performance should be the same.

> > As for .NET vs C++, I somehow always assume C++ will fare better
> > than .NET since it is compiled into native machine language
> > whereas .NET is compiled into MSIL which later run on top of CLR.

> > Please somebody correct me if I'm wrong :)

> > Regards,
> > Hardono Arifanto
> > -----------------------http://sodeve.net


> > > Hi All,
> > > I am looking for some interesting article about performance comparison
> > > between .net and c++, possibly provided with benchmarks.
> > > I have searched the web but i've had very few luck,seems like there is
> > > very little information about this issue.
> > > Can you tell me anything about this argoument?
> > > Is it true that c# and vb.net have the same performance? MS says so,
> > > but i've read somewhere that it is not always true, particularly
> > > regarding the i/o and filesystem management, where c# was supposed to
> > > be faster.
> > > I am particularly interested in performance rearding usage and
> > > manipulation of strings, array, hastables, i/0, filesystem directory
> > > handling.I am not interested in UI, graphical applications and other
> > > stuff like this, because my applications is a batch task, it will run
> > > in background on a server as a windows service.

> > > Thanks in advance
> > > Antonello- Hide quoted text -

> > - Show quoted text -

 
 
 

.NET Performance comparison

Post by Joe Eno » Thu, 29 Mar 2007 23:09:43


If I can comment on something:

Quote:> 2. Pass objects or large arrays using the "ref" keyword - this will
> prevent .NET from making a copy of the object when it is passed to
> another method.

Anytime you pass a reference variable, like an array or other object
with a class type, you are automatically passing the object by
reference, and therefore the "ref" keyword is unnecessary.  If you
pass a reference variable using "ref", then the reference itself is
passed by reference.  For example, if your method reassigns the
variable to a different object while using "ref", then the original
variable now refers to the new object.  If you do the same thing
without using "ref", then the original variable still refers to the
original object, even though the method parameter refers to the new
one.  Either way, the object did not have an extra copy made.

The traditional "by reference" definition is only useful when passing
"by value" objects, like those with a struct type.

 
 
 

.NET Performance comparison

Post by Cerebru » Fri, 30 Mar 2007 05:20:50


My thoughts exactly, Joe. (Ok, I confess, you beat me to it...)

You're absolutely right, Reference types do not need to be passed by
ref. While I always practice most of Jeff's pointers for good
performance, he needs to be aware of this little caveat, that most
people are confused about. Passing a reference type variable by ref is
only necessary if you want to be able to change it within the target
method.


Quote:> If I can comment on something:

> > 2. Pass objects or large arrays using the "ref" keyword - this will
> > prevent .NET from making a copy of the object when it is passed to
> > another method.

> Anytime you pass a reference variable, like an array or other object
> with a class type, you are automatically passing the object by
> reference, and therefore the "ref" keyword is unnecessary.  If you
> pass a reference variable using "ref", then the reference itself is
> passed by reference.  For example, if your method reassigns the
> variable to a different object while using "ref", then the original
> variable now refers to the new object.  If you do the same thing
> without using "ref", then the original variable still refers to the
> original object, even though the method parameter refers to the new
> one.  Either way, the object did not have an extra copy made.

> The traditional "by reference" definition is only useful when passing
> "by value" objects, like those with a struct type.

 
 
 

.NET Performance comparison

Post by vwd-cms.co » Fri, 30 Mar 2007 15:16:25


Hi guys, thanks for pointing this out, it must have been a carry-over
from "old-school" programming days. Sorry for giving bad advice on the
ref issue, but the good news is that this has probably cleared up when
to use ref for anyone reading this thread. Hopefully the other points
I made are valid and will be helpful to devs who are new to writing
code with performance in mind.

-Jeff

 
 
 

.NET Performance comparison

Post by Cerebru » Fri, 30 Mar 2007 16:00:41


Your points are definitely valid, Jeff. Thank you for contributing...


Quote:> Hi guys, thanks for pointing this out, it must have been a carry-over
> from "old-school" programming days. Sorry for giving bad advice on the
> ref issue, but the good news is that this has probably cleared up when
> to use ref for anyone reading this thread. Hopefully the other points
> I made are valid and will be helpful to devs who are new to writing
> code with performance in mind.

> -Jeff

 
 
 

1. Performance comparison of SQLOLEDB versus native SQL Server data provider

I'm writing a database helper component for a web application for use within
our company. This component will interface with a SQL Server 7.0 database
for now, but that might change to another database - possibly Oracle - in
the future (unlikely, but possible). Right now I have two options:

1. Write the helper class for use with the native SQL Server data provider,
and make sure the class consumers never have to use any SqlClient-specific
types. This means I will have to provide a custom type (struct) for passing
parameters, and convert these parameters to SqlParameter within the helper
class (BTW, if anybody of you has another suggestion to solve this problem
I'd appreciate it). If we switch to another database in the future, I would
have to change the types used by this class (SqlCommand to OleDbCommand,
etc.), but the code of the class consumers wouldn't need any changes.

2. Write the helper class for use with OleDb (i.e. use the SQLOLEDB
provider). If we choose this option, I wouldn't have to create any custom
types, and the application would continue to work if we would switch to
another database.

Obviously, option 2 is easier, requires less work and is less error-prone.
Option 1 is faster, however (as long as we keep using SQL Server, which is
very likely). So the big question here is:

"How big is the performance difference between using the native SQL Server
provider and using the SQLOLEDB provider ?"

Are there any bechmarks, test results, analyses, etc... online ? I would
really like to know how much performance is sacrificed if we decide to
choose option 2.

Thank you in advance.

2. Amiga 2000 & Commodore Disk Drives.

3. Performance comparisons (OleDbDataAdapter v/s SqlDataAdapter)

4. Varmit′s audio tools

5. Performance Comparison: Data Access Techniques

6. Eudora - popper question

7. Performance Comparison of ADO vs ADO.NET vs ODBC

8. Comparison of Performance Issues with C#

9. Performance comparison between objects and include files

10. Database Update Performance question/comparison

11. Comparison of '.NET SqlClient' and 'OLEDB' for accessing MSSQL 7 and above

12. XPath query: .NET DateTime type and schema dateTime type comparison.