{"id":8061,"date":"2013-10-22T19:47:07","date_gmt":"2013-10-23T00:47:07","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=8061"},"modified":"2013-10-22T19:47:07","modified_gmt":"2013-10-23T00:47:07","slug":"the-effects-of-compiler-optimizations","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2013\/10\/22\/the-effects-of-compiler-optimizations\/","title":{"rendered":"The Effects of Compiler Optimizations"},"content":{"rendered":"<p>A great <a href=\"http:\/\/stackoverflow.com\/questions\/19470873\/why-does-gcc-generate-15-20-faster-code-if-i-optimize-for-size-instead-of-speed\">question on Stack Overflow<\/a> (via <a href=\"https:\/\/twitter.com\/Catfish_Man\/status\/391713689973186560\">David Smith<\/a>):<\/p>\n<blockquote cite=\"http:\/\/stackoverflow.com\/questions\/19470873\/why-does-gcc-generate-15-20-faster-code-if-i-optimize-for-size-instead-of-speed\"><p>I first noticed in 2009 that gcc (at least on my projects and on my machines) have the tendency to generate noticeably faster code if I optimize for <strong>size<\/strong> (<code>-Os<\/code>) instead of speed (<code>-O2<\/code> or <code>-O3<\/code>) and I have been wondering ever since why. <\/p>\n<p>I have managed to create a (rather silly) code that shows this surprising behavior and is sufficiently small to be posted here. <\/p><\/blockquote>\n<p>There&rsquo;s so much going on in modern processors that it can be tough to predict how code will behave.<\/p>","protected":false},"excerpt":{"rendered":"<p>A great question on Stack Overflow (via David Smith): I first noticed in 2009 that gcc (at least on my projects and on my machines) have the tendency to generate noticeably faster code if I optimize for size (-Os) instead of speed (-O2 or -O3) and I have been wondering ever since why. I have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[45,255,75,285,138,71],"class_list":["post-8061","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-compiler","tag-developertool","tag-gcc","tag-optimization","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=8061"}],"version-history":[{"count":0,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8061\/revisions"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=8061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=8061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=8061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}