Vs-driven unmanaged physical engines for C #

Has anyone tried the BEPU Physic Engine? http://bepuphysics.codeplex.com/

This is a fully managed physics engine written in C # ... I know that it is mainly used for XNA (XBOX and WP7 projects), because unmanaged codes are not allowed.

But I want to know how a fully managed physics engine compares to P / Invoked One (e.g. tao.ODE) in a Windows environment (in terms of performance )?

In other words, which method does more overhead, fully managed code, or P / Invoke Wrapper around unmanaged engines like ODE or PhysX in a real project?

+4
source share
2 answers

I cannot comment on specific physical engines, but I can offer some experience writing high-performance code (both unmanaged and managed).

A few years ago, I was working on modeling software written in Delphi and ported to .NET (I could say before I arrived). It was a clean controlled code and calculated ion trajectories for modeling mass spectrometers. The code included numerical integration, differentiation, calculations of the electrostatic charge of the N-body, so, of course, CPU testing.

I found in various experiments, trying to find the best performance, that some versions of C ++ versions of simulation routines can be beaten with well-optimized C # code.

Well-optimized, I mean reducing new operators (reusing objects), caching, combining objects, using possible structures, minimizing method calls, where possible, invoking a static / sealed processing method, where possible, minimizing the number of parameters passed methods, compile in release, x64, separate from the debugger. Once I did this to beat the CLR using C ++, I had to resort to low-level methods such as SSE / SSE2 and built-in assembler.

Well, I agree that C # and managed languages ​​are not suitable for manually optimized C ++ code in experienced hands, but I have seen poorly optimized code on both platforms. It's easy to blame the CLR when C # code is slow, but when developers use the new operator as they see fit, I find this strange, they wonder when the GC works so often. new and delete in C ++ is also a performance hit, so don't expect C ++ compilation to just speed things up.

Let's get back to your specific engine - of course, you will have to conduct some tests and performance analysis yourself. As for calling the platform, this leads to a performance hit known as thunking, when pointers and structures are sorted by managed / unmanaged border. Pure managed code will not have this, but it will also miss out on optimizations such as low-level memory copy, SSE / SSE2 extensions, etc ... that can be encoded in C ++.

Finally, I will say that for an example of a managed -> Platform invoke library, which is extremely powerful and fast, take a look at SlimDX . It’s good that you will get the performance that got into your own code and DirectX (some sources say ~ 5%), but to increase the development productivity in C # I would say that it is worth it!

Yours faithfully,

+5
source

but I want to know how a fully managed physics engine compares to P / Invoked One (for example tao.ODE) in a Windows environment (in terms of performance)?

Both suck are the only way to get real high performance these days, they are not "uncontrollable", as in the "processor code", but "uncontrollable", as when "starting on the video card".

+1
source

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


All Articles