I understand the behavior of const -qualified data types. I am curious, however, if there is any profit or loss of performance from the excessive or perplexing qualifying variables as const . I think, in particular, about variables declared and used exclusively in an isolated block of code. For example, something like:
const qreal padding = CalculatePadding(); const QSizeF page_size = CalculatePagePreviewSize(padding); const QRectF content_rect = CalculatePagePreviewContentRect(page_size); const QList<QRectF> pages = renderer.BuildPrintPages(printer_, map_scene_); const QFont page_number_font = CalculatePageNumberFont(); const QFontMetrics metrics(page_number_font);
Suppose I only need const -qualified methods for all of these (and more). Is there any performance gain when declaring them all const ? Or, conversely, does it really degrade performance?
I'm curious about both runtime performance (I assume it doesn't matter since const is just a compile-time check - can someone confirm?) And compilation performance. I do not have enough experience with C ++ to understand this, and I wonder if I should be mistaken on the side of over- or under-apply const , when all other things (maintainability, etc.) are equal.
c ++ performance const
Dave mateer
source share