Jump to content



Photo

  • Please log in to reply
26 replies to this topic

#16 OP henriko

henriko

    Neowinian

  • Joined: 29-May 12

Posted 31 May 2012 - 17:53

Thank you all for all good advice, and comments. I guess I will take a peak into C++11 at least to evaluate a little more what the fuzz is all about. I guess some sort of combination would be the best choice, frontend in C#, back-end core algorithms in C++. I have done some benchmarks on my own and C# always comes out slower and sometimes significantly slower, even though I try to do all the tricks with unsafe etc. But I don't consider myself a performance guru, and I could be missing something. Operations I have tested is image filtering, mean filtering and such. It's a shame actually, in the beginning I believed if I just did all the small tricks (unsafe, i < array.Length etc) I could squeeze out more performance of C# and make it at least very close to C++ (of course not counting the startup time and JITing and such). But in my experience even simple C++ for loops is way better, no tricks (release code that is!). After doing my own small performance tests I started scanning the net for more on the matter, in case I was missing something, which finally ended up in this post.

[quote name='Aethec' timestamp='1338482211' post='594899501']
Microsoft has some working prototypes of fully managed OSs, some public ones (e.g. Singularity) and some internal ones (e.g. Midori, see http://webcache.goog...lient=firefox-a ).
Apparently, they've also created a "language like C# that has the performance characteristics of C++" ( http://www.microsoft...-94035/1514399/ 2nd sentence of 2nd paragraph).

Their sudden love for C++ is a way to tell native developers they haven't forgotten C++ exists.
[/quote]

Interesting, C++ like performance is the only thing I'm missing from C#. One of the reason I wrote the post as well was my growing worry that Microsoft's new love for C++ would somehow reduce the effort put into significantly improving .NET performance (like for instance SIMD). Thanks for the heads up!

[quote name='_heracles' timestamp='1338482218' post='594899503']
That is an odd first post
[/quote]

Maybe. My main reason for writing the post was to start a discussion about the future of C#, .NET and C++11 in light of the sudden outburst from Microsoft around C++. Since I'm also have personal reasons for considering a switch to C++11 (starting a big project with extreme performance requirements), I thought that was valuable information. It's not like I would consider switching to C++ if I was going to write a mainly GUI centric application, that would just be dumb. I was also eager to hear other posters opinions, especially I wanted to hear what Dr_Asik had to say, since I actually first posted this post as a comment to one of his blog post about C# being the future for Console development.

[quote name='simplezz' timestamp='1338482111' post='594899495']
Why would coding in C# be any faster? If you use libraries like Boost, C++ apps can be coded pretty fast provided you start out with a solid design.
[/quote]

In my experience it's faster, but that’s not very objective I know :-) It’s also the responses I have got at several occasions from co-workers and customers, and Herb says so also in his videoes. I should probably add I code mostly GUI centric applications with rich interaction experiences. There might be a good chunk of libraries for C++ doing that a lot easier now (Qt or similar probably), but around 10 years ago when I started out with my transition via. VB 6.0 towards C# there was very little, at least that I knew of. I was coding MFC, oh horrible!

[quote name='RATiO' timestamp='1338485929' post='594899667']
what is a "coffee based coder"?
[/quote]

It's what Herb Sutter calls you if you code managed languages. Take a look at the videoes ;-)


#17 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 17
  • Joined: 26-October 05

Posted 31 May 2012 - 18:11

There's absolutely nothing esoteric about templates, maybe you should look up the definition of esoteric programming languages...

The fact that the Turing-complete template metaprogramming language was an accident, not a design decision, and that the syntax and behavior are nothing like the rest of C++, break most compilers and cannot be understood by even most expert C++ programmers, makes it esoteric in my book.

Did you know that because templates are Turing-complete, it's impossible to determine whether a valid C++ program can be compiled without solving the halting problem - i.e. it's impossible?

Funny to read that out of the mouth of a .NET supporter - name the redundancies in the C++ standard library than...

Most of the C++SL is duplicate features from the C library which is also in the standard C++SL, to begin with...

Niche status? You do realize that almost everything sold by Microsoft (including Windows, Office, Visual Studio and so on) is written in C and C++?! Not to mention that the industry reinforces it's focus on C++ as "the free lunch" is over...

Demand for C++ developers has steadily been on the decline for more than a decade now. C++ remains relevant where significant C++ codebases already exist and the rewrite effort isn't worth it - which is case for most Microsoft products - or where the performance requirements really justify it, which is a minority of software given that you already get pretty damn good performance for a lot less effort with .NET.

As for the industry "reinforcing its focus on C++"... all I see is some Microsoft evangelists trumpeting C++11 like lambdas or very limited inference were equivalent to a re-birth.

#18 OP henriko

henriko

    Neowinian

  • Joined: 29-May 12

Posted 31 May 2012 - 18:32

Since it might be of interest to others as well, here is some numbers from a quick performance test I performed. The problem was median filtering of an image:

(1) C++ AMP (same quick_select code as below just AMPified, included copying of data to the GPU) – 1.4ms

(2) MATLAB (using medfilt2 with uint8 data, IPP acceleration) – 4.4ms

(3) MATLAB .NET component called from C# code (including copying of data between programs) – 5.1ms

(4) Python OpenCV medianBlur (I guess with IPP acceleration) – 8ms

(5) C++ using quick_select instead of quicksort – 298ms

(6) MATLAB (using the normal built in medfilt2 with double data) - 399ms

(7) NumPy (4 for-loops) - 533ms

(8) C# Parallel.For (same 4 for-loops as below) - 865ms

(9) C++ (4 for-loops using quicksort) - 997ms

(10) C# (4 for-loops using quicksort) - 1129ms

(11) MATLAB (4 for-loops using quicksort) – 5200ms

(12) Python (4 for-loops using quicksort) - 16400ms



#19 CentralDogma

CentralDogma

    Neowinian Senior

  • Joined: 29-February 08

Posted 31 May 2012 - 19:09

Also, make sure your running benchmarks in a production-similar environment. OS/hardware can have an effect on these things, so make sure you’re targeting the actual machine this code is going to run on and not your development machine.

#20 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 17
  • Joined: 26-October 05

Posted 31 May 2012 - 19:26

It's what Herb Sutter calls you if you code managed languages. Take a look at the videoes ;-)

From what I remember he called Java and C# "coffee languages" (because Java = coffee), but he didn't call the programmers themselves "coffee-based coders".

#21 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 17
  • Joined: 26-October 05

Posted 31 May 2012 - 20:26

Since it might be of interest to others as well, here is some numbers from a quick performance test I performed. The problem was median filtering of an image:

(1) C++ AMP (same quick_select code as below just AMPified, included copying of data to the GPU) – 1.4ms

(2) MATLAB (using medfilt2 with uint8 data, IPP acceleration) – 4.4ms

(3) MATLAB .NET component called from C# code (including copying of data between programs) – 5.1ms

(4) Python OpenCV medianBlur (I guess with IPP acceleration) – 8ms

(5) C++ using quick_select instead of quicksort – 298ms

(6) MATLAB (using the normal built in medfilt2 with double data) - 399ms

(7) NumPy (4 for-loops) - 533ms

(8) C# Parallel.For (same 4 for-loops as below) - 865ms

(9) C++ (4 for-loops using quicksort) - 997ms

(10) C# (4 for-loops using quicksort) - 1129ms

(11) MATLAB (4 for-loops using quicksort) – 5200ms

(12) Python (4 for-loops using quicksort) - 16400ms

So this is orders of magnitude faster with GPU acceleration than without; it's about 3 times faster with QuickSelect than QuickSort; and using the same algorithm, it's about 10% slower in C# than C++. That seems about right.

Using WinRT it's easier than ever to call C++ components from C#, so since AMP is C++-only, typically you'd write the app in C# and call into the C++ AMP component if and when required.

#22 OP henriko

henriko

    Neowinian

  • Joined: 29-May 12

Posted 31 May 2012 - 21:11

Yes, the C++ AMP results was insane :-) It was really easy to change the original code as well, only a couple of lines of the program had to be changed. GPU acceleration is way to go!
Will try out the mixing of C++ and C# in WinRT, haven't been experimenting much with Win8 programming just yet. Downloading VS 2012 preview as we speak...

#23 tiagosilva29

tiagosilva29

    Looking for a job in Lisbon

  • Tech Issues Solved: 1
  • Joined: 08-May 04

Posted 31 May 2012 - 21:48

Nice try,

Bjarne.



#24 helios01

helios01

    Neowinian

  • Joined: 30-April 07

Posted 01 June 2012 - 04:28

Well there is also web development with C#/ASP.NET (MVC) which is making great strides forward nowadays, so unless C++ becomes a web language, it's hard to see C# going away even if C++ somehow replaces C# in the desktop apps space. A mix may indeed be the best option. I hope XNA doesn't go away, I quite enjoy coding with it and it's an important component (only way to do graphics-intensive apps) for Windows Phone.

#25 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 17
  • Joined: 26-October 05

Posted 01 June 2012 - 13:20

I hope XNA doesn't go away, I quite enjoy coding with it and it's an important component (only way to do graphics-intensive apps) for Windows Phone.

Me neither. I'm totally ****ed at MS for not supporting XNA for Metro, and probably not working on another version of XNA at all. SharpDX, although great, is no replacement for a high-level, novice-friendly and cross-platform API.

In the meantime, however, the APIs are being reimplemented as the open-source project MonoGame, which supports every platform from Android to Metro, and is apparently quite popular already.

#26 OP henriko

henriko

    Neowinian

  • Joined: 29-May 12

Posted 02 June 2012 - 08:06

I hope XNA doesn't go away, I quite enjoy coding with it and it's an important component (only way to do graphics-intensive apps) for Windows Phone.



You should keep an eye on ANX (http://anxframework.codeplex.com/), they are using SharpDX and creating a high level wrapper.

"The first goal is to create a 1.0 version which has the same features as XNA and which behaves the same way"

#27 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 17
  • Joined: 26-October 05

Posted 02 June 2012 - 13:20

You should keep an eye on ANX (http://anxframework.codeplex.com/), they are using SharpDX and creating a high level wrapper.

Seems pretty dead to me already. No real progress made since March if you look at the commits. MonoGame is already much more mature, making progress at a steady pace and being used in many real-world projects.