C++ defines for a 'better' Release mode build in VS
Asked Answered
G

1

6

I currently use the following preprocessor defines, and various optimization settings:

  • WIN32_LEAN_AND_MEAN
  • VC_EXTRALEAN
  • NOMINMAX
  • _CRT_SECURE_NO_WARNINGS
  • _SCL_SECURE_NO_WARNINGS
  • _SECURE_SCL=0
  • _HAS_ITERATOR_DEBUGGING=0

My question is what other things do fellow SOers use, add, define, in order to get a Release Mode build from VS C++ (2008,2010) to be as performant as possible?

btw, I've tried PGO etc, it does help a bit but nothing that comes to parity with GCC, also I'm not using streams, the C++ i'm talking about its more like C but making use of templates and STL algorithms etc.

As it stands now very simple code segments pale in comparison wrt performance when compared to what GCC produces on say an equivalent x86 machine running linux (2.6+ kernel) using 02.

Side-Note: I believe a lot of the issues relate directly to the STL version (Dinkum) provided by MS. Could people please elaborate on experiences using STLPort etc with VS C++.

Gillam answered 17/3, 2010 at 5:59 Comment(3)
You should also list the settings you've specified in your project properties under C/C++, Optimization and possibly also under C/C++, Code Generation, because these can greatly affect the optimization that the compiler will do.Byran
Most of those have no impact on performance, but simply remove warnings or speed up compilation. Anyway, in my experience, VC++ and GCC produce code that performs about equally well. How big a difference are you seeing, and exactly how is each compiler invoked?Dagostino
This is not performance related, but you should consider using banned.h from Microsoft's SDL for a Win32 app.Moina
K
1

I don't see how the inclusion of:

_CRT_SECURE_NO_WARNINGS
_SCL_SECURE_NO_WARNINGS

..gives you a better or more performant build. All you are doing is disabling the warnings about the MS CRT deprecated functions. If you are doing this because you know what you are doing and require platform agnostic code fine, otherwise I would reconsider.

UPDATE: Furthermore the compiler can only do so much. I'd wager you would get more performant code if you instrumented and fixed your existing hotspots rather than trying to eek tiny percentage (if that) gains from the compiling and linking phase.

UPDATE2: _HAS_ITERATOR_DEBUGGING cannot be used when compiling release builds anyway according to the MSDN. WIN32_LEAN_AND_MEAN VC_EXTRALEAN (and probably NOMINMAX although performance isn't the chief reason to disable this) might give you some performance boost although all the rest have dubious value. You should favour correct fast code over (maybe - and I stress maybe) slightly faster but more risk prone code.

Kentish answered 17/3, 2010 at 13:33 Comment(22)
I agree completely, but I must add that performant is NOT a word.Demona
In the absence of a more suitable word what is the renegade linguist to do? Eventually the dictionaries will catch on. :-) (According to Jeff Boulter anyway)Kentish
@Charles: According to Dictionary.com, it is. It's a performer in the same way an informer is an informant. However, I think this is a more than suitable word to express the concept and, after all, English dictionaries are descriptive rather than prescriptive.Shiprigged
@Kaz Dragon - If you look at where dictionary.com is getting that definition from, it is from "Dictionary.com's 21st Century Lexicon", which is not an actual dictionary, which means that it is slang, and not even slang that real dictionaries even acknowledge, like "ain't". And even though MOST English dictionaries are descriptive, it doesn't mean you should just make up words because you can. Exactly what is wrong with using "better performing" instead of "more performant" in the statement here. It uses real words and still conveys the exact same meaning.Demona
@Charles: you're really fighting a losing battle here. I predict within 20 years or so, dictionaries will be utterly useless. If you want to restrict yourself to using only formally-defined words, that's fine, but don't expect to be able to function in modern society...Kitchenmaid
@STingRaySC that is one of the most ridiculous comments I've ever seen. Dictionaries will be useless? I don't even know how someone with a modicum of common sense could ever think that. Yes, new words are created and eventually become part of the language, but using words that have not reached that point in any sort of professional setting just makes you look ignorant to your peers and superiors.Demona
@Charles: that's funny, because I would have expected someone with a modicum of common sense to realize I was being facetious.Kitchenmaid
@Charles: Oh, and just how do you think words "... [reach] that point in any sort of professional setting"? Maybe, by using them?! Just let go of it. The English language is decaying before our eyes. You can't stop it! Consider yourself fortunate when you can understand enough of the words that someone utters to have some basic semblance of what he/she is trying to communicate.Kitchenmaid
It's not decaying, @Stingray; it's changing. New words come into existence. Old words acquire new meanings. Some meanings go away. It's a process that's been happening for hundreds of years.Swimmingly
Slang words are still words, @Charles. I don't see how you can say that the word doesn't count because the definition comes from "Dictionary.com's 21st Century Lexicon." Lexicographers found the word and composed a definition based on how they observed it being used. What difference does it make whether they were working for Dictionary.com or Merriam-Webster? What distinguishes something that looks like a dictionary from an "actual dictionary"? I promise you Konrad did not "make up" performant. It's a word used all the time. wordnik.com/words/performantSwimmingly
Getting back on topic: Do the "lean" macros really affect performance at all? I though they were meant to control which headers, functions, types, and other identifiers would get included when you #include <windows.h>. It doesn't affect any executable code, does it?Swimmingly
Bah, the English language would be so much better off if no one ever used it! Just like Latin. ;) As for "performant", I've seen the word used quite often. If you want to talk about looking ignorant, I'd say pretending not to understand the word is a better way to do it.Dagostino
@Rob Correct. Whether this leads to improved execution speed or simply a reduced binary size I don't know.Kentish
@Rob - the difference is that slang words (and non-standard definitions) should not be used when writing something in a professional context. I know that some people think that writing on the web is not a professional context, but on a site like this, and on the many technical blogs that decide to use this non-word, it most definitely is a professional context.Demona
@Rob - also, as for the validity of "Dictionary.com's 21st Century Lexicon.", all you need to do is talk to a linguist or a grammarian. Ask them to give you a list of sources that could be defined as valid sources of English language knowledge. Dictionary.com will not be one of them (except for when their source is one of the "real" dictionaries).Demona
@Charles: I would, but I don't happen to know any linguists or grammarians, and I'm pretty sure I don't want to know any. They serve roughly the same purpose as a corporate ethics committee. Also, you may wish to reconsider your use of the term "non-word," as I'm not able to find it in any reputable dictionary (closest match is "nonword," so I'll go ahead and assume that's what you mean). If you think linguistic and grammatical accuracy is paramount in a venue such as this, perhaps you should be examined for OCD. Medication could make it much easier for you to use stackoverflow.Kitchenmaid
@Charles: Arnold Zwicky is a linguistics professor at Stanford. He cited Dictionary.com's lexicon as a source in his own research earlier this year: arnoldzwicky.wordpress.com/2010/02/28/ottles. Also, I should have said before that I disagree with your classification of the word as slang. If labeled as anything, it's jargon, and when writing in a professional context, it's perfectly acceptable to use jargon from the profession you're writing about. Performant is a real word; absence from a dictionary doesn't change that.Swimmingly
I wish people would have commented this much on the actual questionation rather than talkifying my usinglyness of the word "performant"! :>Gillam
@konrad: Regarding _CRT_SECURE_NO_WARNINGS and _SCL_SECURE_NO_WARNINGS its more about bringing some sanity to the compiler diagnostics rather than optimisations.Gillam
@konrad: Regarding _HAS_ITERATOR_DEBUGGING, believe it or not it does have a positive effect on performance for release mode compilations - give it a try,Gillam
@konrad: Regarding optimisation flags, I've used them all, fast code, full optimisation etc.. basically I've found fast code and to favour fast code over small code to be the best option. when doing PGO, the result is roughly 1%-2% better which is not that useful when considering how long it takes to perform PGO and the issues of compiling highly complex structured code for production purposes using PGO.Gillam
@darid - how exactly do '_CRT_SECURE_NO_WARNINGS' and '_SCL_SECURE_NO_WARNINGS' bring more sanity to compiler diagnostics? Also this question is about optimisations hence the reason I highlighted them. Also I think you've missed the point, rather than using PGO blinding - /instrument/ your code in real world tests and improve hotspots. That done well will be a better use of your time and give you a better code base.Kentish

© 2022 - 2024 — McMap. All rights reserved.