简体   繁体   中英

Visual Studio C Performance

I have a C project (compiled as lib) in Visual Studio 2010. Functions from this library are then called from C++ (native, no CLR). My question is: Does Visual Studio compiler produce for plain C as fast binary code as it would for C++? Is there any performance penalty for plain C? I hope there is not, but I would like to be sure.

In another words, does VS2010 optimize C++ better than C?

There should be no performance penalty to call C functions from C++. The only way you'll know for sure is by profiling your code or by looking at the generated instructions.

Visual C++ uses the same code generation back-end for both C and C++, so it will generally produce identical output for equivalent input.

There are some things you can do in C++ (eg, using templates) for which C provides no (reasonable/practical) equivalent. In some of these cases, C++ can (and typically will) allow you to write code that's more efficient than a typical equivalent in C. For example, std::sort is frequently faster than qsort (and not just a tiny bit faster either -- a factor of 2 or 3 is fairly common).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM