[.net] C# Fast like hell

Started by
8 comments, last by ToohrVyk 15 years ago
After an simple benchmark I did comparing how fast to build and iterate through a list of integers made of 1000,1000 elements, i was surprised to see that C# was fast like hell compared to C++, which was disappointingly slow. How come C# is fast that even faster than what should be the normal sense...
Advertisement
I find that artificial benchmarks usually give artificial results.
Most likely you are fooled.
Your benchmark is invalid. It probably doesn't tell you what you think it tells you, if that.

Why don't you provide us the code, input, and output for the benchmark and described the environment you built (for example, did you enable optimizations?) and executed it under.
When i was working with C#, as a learning exercise I made a simple gravity particle simulator, this was on XNA. Storing all the particles in large arrays I was about to push about 300k particles with 3 gravity wells at 20fps. I ported it over to C++, surprisingly the performance was nearly the same! It was only after reimplementing the algorithm in SIMD was i able to beat the C# version, by a factor of ~3. So I would say C# will give acceptable performance for most things.

Your experience may vary :D

Enjoy!

-ddn
After going throug the code again and trying to replace the C++ list with array, then C++ is 10 times faster. And in fact C# List implementation is actually faked by array so that it gives performance gain...nvm
Quote:Original post by Sambori
C# List implementation is actually faked by array
It's not faked at all, it's explicitly called out in the documentation that List<T> is implemented as an array.
Quote:Original post by Sambori
After going throug the code again and trying to replace the C++ list with array, then C++ is 10 times faster. And in fact C# List implementation is actually faked by array so that it gives performance gain...nvm

Your benchmark is still invalid. It probably doesn't tell you what you think it tells you, if that.

Why don't you provide us the code, input, and output for the benchmark and described the environment you built (for example, did you enable optimizations?) and executed it under.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Any c++ code being 10x faster than c# is ridiculous, clearly you're doing something wrong. Are you in debug mode? Are you using reference types for something that's frequently instanced?

In my experience, even extremely tight, mathematically complex code can have similar performance in c# or c++. I ported a c++ procedural noise library from c++ to c# and was able to get it to within 10% or so of the c++ performance (although admittedly it did require a lot of knowledge of writing optimized .net code to pull that off).

Again, while in my experience you can never get quite the same performance in c#, it's close enough to not be a big deal (and to be worth the more rapid development imo).
Quote:Original post by Sambori
After going throug the code again and trying to replace the C++ list with array, then C++ is 10 times faster. And in fact C# List implementation is actually faked by array so that it gives performance gain...nvm


List != linked list : both linked lists and dynamic arrays are implementations of the list abstract data type.


A C# List is a list, implemented as a dynamic array.
A C++ std::vector is a list, implemented as a dynamic array.

A C# LinkedList is a list, implemented as a linked list.
A C++ std::list is a list, implemented as a linked list.


This topic is closed to new replies.

Advertisement