{"id":3998,"date":"2014-03-30T07:04:06","date_gmt":"2014-03-30T07:04:06","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/running-time-of-an-application-in-visual-studio-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:04:06","modified_gmt":"2014-03-30T07:04:06","slug":"running-time-of-an-application-in-visual-studio-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/running-time-of-an-application-in-visual-studio-collection-of-common-programming-errors\/","title":{"rendered":"Running time of an application in Visual Studio-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3a75bbd20c63eb9b569fa7617fa6b4ef?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nShakehar<\/p>\n<p>I am solving some algorithm problems in c# and running them as a console application.<\/p>\n<p>To check for the efficiency of the applications I would like to see what their run times are.<\/p>\n<p>Currently I am printing the time at the start of a program and at the end and calculating the time difference ,but is there a way to reduce Observer&#8217; effect ?<br \/>\nSome inbuilt tool\/plugin that I am not aware of ?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7deca8ec973c3c0875e9a36e1e3e2c44?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSLaks<\/p>\n<p>You should use the <code>Stopwatch<\/code> class, which is specifically designed to do that.<\/p>\n<p>To avoid measuring the JIT time, you should also run each algorithm at least once before measuring anything so that the JIT has time to run.<\/p>\n<p>When measuring the algorithms, you should run each one hundreds of times and take the average runtime.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/unknownerror.org\/Problem\/index\/-1264848476\/running-time-of-an-application-in-visual-studio\/\" \/><br \/>\nuser694833<\/p>\n<p>The most important source of delay due to observer&#8217;s effect is printing itself. Another potential delayer is debug message text formatting. So I suggest the following:<\/p>\n<ul>\n<li>If you can anticipate the number of loops and number of stages per loop, create an array to store timing information. If not, use a dynamic list.<\/li>\n<li>During execution, store time and aditional information in that array or list.<\/li>\n<li>If possible, don&#8217;t store messages along with time but codes, for example 1=Stage 1, 2=Stage 2, etc.<\/li>\n<li>At the end of the execution, dump all the information to screen or file, and format messages as needed.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Shakehar I am solving some algorithm problems in c# and running them as a console application. To check for the efficiency of the applications I would like to see what their run times are. Currently I am printing the time at the start of a program and at the end and calculating the time difference [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3998","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3998"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3998\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}