C # Performance - Should I write complex calculation methods in C ++?

I am creating a prototype for a quantitative library that does some signal analysis using image processing methods. I completely created the original prototype in C #, but the performance is not as good as expected. Most of the calculations are performed using heavy matrix calculations, and they take up most of the time.

I am wondering if it's worth writing a C ++ / CLI interface for unmanaged C ++ code. Has anyone ever gone through this? Other suggestions for optimizing C # performance are welcome.

+3
source share
8 answers

There was a time when it would definitely be better to write in C / C ++, but the C # optimizer and JIT are so good now that there is probably no difference for pure math.

The difference arises when you have to deal with memory and possibly arrays. However, I was still working with C # (or F #) and then would optimize the hotspots. JIT is really good at optimizing small, short-lived objects.

With arrays, you need to worry about C # fulfilling restrictions - checking every access. Read this:

http://blogs.msdn.com/b/clrcodegeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx

Test it yourself - I believe C # is comparable - sometimes faster.

+3
source

, , .

- , , ++ # - ++ , CLR JITER , . ++ # .

. . , .

, ++/CLI , . , , , - .

+3

, . ++ , LAPACK.

# LAPACK ( # BLAS ), , , , .

+2

#, , , , , PInvokes, ++/CLI. .

.NET. Red Gate - . , .

+1

++, ++-, #. , . ++, # , .NET ++. , # , - ++. # ++, ++, - #.

x - ++, y - #, x , y. y , x .

0

#. gobbsmacked, , #. # ++, , Sin, Cos,... .

, ++, imlpementing ++ abd umagine P/Invoke .

, .

0

#, , .

:

++ , #. , , , , , . ++. # ++, ++, , . . ++. , , # Java, - .

, , , #, , .

, ( , , ). , , .

- ++ , , Fortran ( ), ( ) , .

? # ?

0

Source: https://habr.com/ru/post/1775222/


All Articles