C# as fast as C++
Ok, ok, ok, just let me explain... I'm completely fed up with the following comment
yes, but you have a performance penalty because your code is .NET. (Uhm... Do I have to remind somebody we are faster than the
faster doing updates)The last one was an small argument this morning when I heard that C++ was supposed to do
printf faster than C# does
WriteLine... God! I was supposed to be a C++ coder wannabe for years, but, admitedly, now I love C#. I felt in love as soon as I discovered Remoting... And I basically love Mono for the same reason. Hey! I have a DCOM background, understand it!
And, well, I just arrived home and I had to have a look into it! So, here is the nice C# code:
static void Main(string[] args)
{
int num = Convert.ToInt32(args[0]);
for( int i = 0; i < num; ++i )
{
Console.WriteLine("{0}", i.ToString());
}
}
Against it C++ enemy:
int _tmain(int argc, _TCHAR* argv[])
{
int num = atoi(argv[1]);
for( int i = 0; i < num; ++i )
{
printf("%d\n", i);
}
return 0;
}
And the results? Well, I tried looping 10 thousand times and:
C# 2023 ms
C++ 2093 msOoops!!! Well, you can conclude definitely they are at the same level, at least doing string printing, and taking into account that the .NET app needs to load the framework... The only issue is that I tried both in Debug mode...
So, please, no more cheap talking on good old C#, right?
:-D
Pablo Santos
I'm the CTO and Founder at Códice.
I've been leading Plastic SCM since 2005. My passion is helping teams work better through version control.
I had the opportunity to see teams from many different industries at work while I helped them improving their version control practices.
I really enjoy teaching (I've been a University professor for 6+ years) and sharing my experience in talks and articles.
And I love simple code.
You can reach me at
@psluaces.
0 comentarios: