Performance of C++ vs Virtual Machine languages in high frequency finance

前端 未结 15 1912
死守一世寂寞
死守一世寂寞 2020-12-12 13:34

I thought the C/C++ vs C#/Java performance question was well trodden, meaning that I\'d read enough evidence to suggest that the VM languages are not necessarily any slower

15条回答
  •  甜味超标
    2020-12-12 13:58

    There are reasons to use C++ other than performance. There is a HUGE existing library of C and C++ code. Rewriting all of that in alternate languages would not be practical. In order for things like P/Invoke to work correctly, the target code has to be designed to be called from elsewhere. If nothing else you'd have to write some sort of wrapper around things exposing a completely C API because you can't P/Invoke to C++ classes.

    Finally, P/Invoke is a very expensive operation.

    JIT compilers are getting better and better. They can do optimizations as the program is running

    Yes, they can do this. But you forget that any C++ compiler is able to do the same optimizations. Sure, compile time will be worse, but the very fact that such optimizations have to be done at runtime is overhead. There are cases where managed languages can beat C++ at certain tasks, but this is usually because of their memory models and not the result of runtime optimizations. Strictly speaking, you could of course have such a memory model in C++, EDIT: such as C#'s handling of strings, /EDIT but few C++ programmers spend as much time optimizing their code as JIT guys do.

    There are some performance issues that are an inherit downside to managed languages -- namely disk I/O. It's a one time cost, but depending on the application it can be significant. Even with the best optimizers, you still need to load 30MB+ of JIT compiler from disk when the program starts; whereas it's rare for a C++ binary to approach that size.

提交回复
热议问题