{"id":258,"date":"2010-01-06T18:26:07","date_gmt":"2010-01-07T00:26:07","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=258"},"modified":"2010-01-06T18:26:07","modified_gmt":"2010-01-07T00:26:07","slug":"exceptions-and-various-compilation-option-speeds","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2010\/01\/06\/exceptions-and-various-compilation-option-speeds\/","title":{"rendered":"Exceptions and various compilation option speeds"},"content":{"rendered":"<p>So after some discussion yesterday with a few folks about Exceptions in C++, I decided to add a compilation flag to disable the use of exceptions in tinypyC++. \u00a0The claim given to me was around these few items: 1. Exceptions slow your code down. \u00a02. Exceptions aren&#8217;t cross-platform (in some cases). \u00a03. Exceptions can easily add in memory-leaks.<\/p>\n<p>I can&#8217;t argue with #2, although it&#8217;s not completely relevant for the platforms I&#8217;m targeting right now. \u00a0#3, with the way tinypyC++ does reference counting, I wouldn&#8217;t be surprised if this could happen. \u00a0#1, I figured might be true, but I wanted to know how real #1 actually was. \u00a0So here are my results:<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<th>g++ flags<\/th>\n<th>ms<\/th>\n<\/tr>\n<tr>\n<td>(none)<\/td>\n<td>894<\/td>\n<\/tr>\n<tr>\n<td>-g<\/td>\n<td>891<\/td>\n<\/tr>\n<tr>\n<td>-O3<\/td>\n<td>414<\/td>\n<\/tr>\n<tr>\n<td>-DTP_NO_THROW -fno-exceptions<\/td>\n<td>894<\/td>\n<\/tr>\n<tr>\n<td>-g -DTP_NO_THROW -fno-exceptions<\/td>\n<td>878<\/td>\n<\/tr>\n<tr>\n<td>-O3 -DTP_NO_THROW -fno-exceptions<\/td>\n<td>378<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In the first test I&#8217;m rendering a Julia fractal for 20 frames and averaging the time it takes to render.  In the second test (below) I&#8217;m doing the same test, but I did one code optimization to remove a new\/delete that was happening for each pixel &#8211; by reusing the coordinates object.<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<th>g++ flags<\/th>\n<th>ms<\/th>\n<\/tr>\n<tr>\n<td>(none)<\/td>\n<td>293<\/td>\n<\/tr>\n<tr>\n<td>-g<\/td>\n<td>290<\/td>\n<\/tr>\n<tr>\n<td>-O3<\/td>\n<td>153<\/td>\n<\/tr>\n<tr>\n<td>-DTP_NO_THROW -fno-exceptions<\/td>\n<td>304<\/td>\n<\/tr>\n<tr>\n<td>-g -DTP_NO_THROW -fno-exceptions<\/td>\n<td>303<\/td>\n<\/tr>\n<tr>\n<td>-O3 -DTP_NO_THROW -fno-exceptions<\/td>\n<td>112<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I found it interesting that in the 2nd test case I did, removing exceptions actually increased the time it took to render the fractal! \u00a0Not quite sure why .. hmmm. \u00a0(I tried it a few times and kept getting similar results too.)<\/p>\n<p>What is clear in the second test is that the compiler is able to optimize the code much more aggressively. \u00a0I guess Exceptions choke up the optimizer. \u00a0In all cases it seems that adding on the -g flag seems to make the code run slightly faster, surprisingly enough! \u00a0(-g adds in debugger info.) \u00a0In all cases, the optimizer was able to roughly double the speed of the program, and when I disable exceptions it is able to throw in even more speed.<\/p>\n<p>-Phil<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So after some discussion yesterday with a few folks about Exceptions in C++, I decided to add a compilation flag to disable the use of exceptions in tinypyC++. \u00a0The claim given to me was around these few items: 1. Exceptions slow your code down. \u00a02. Exceptions aren&#8217;t cross-platform (in some cases). \u00a03. Exceptions can easily [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,6,32],"tags":[],"class_list":["post-258","post","type-post","status-publish","format-standard","hentry","category-c","category-development","category-tinypy"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=258"}],"version-history":[{"count":1,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/258\/revisions\/259"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}