{"id":366,"date":"2009-04-17T13:42:14","date_gmt":"2009-04-17T13:42:14","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/2009\/04\/17\/speeding-up-dougs-solution-with-the-profiler\/"},"modified":"2009-05-19T16:21:14","modified_gmt":"2009-05-19T16:21:14","slug":"speeding-up-dougs-solution-with-the-profiler","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2009\/04\/17\/speeding-up-dougs-solution-with-the-profiler\/","title":{"rendered":"Speeding up Doug&#8217;s solution with the profiler"},"content":{"rendered":"Last week, <a href=\"https:\/\/blogs.mathworks.com\/videos\/2009\/04\/10\/matlab-puzzler-professor-and-the-rain\/\">I posed a Puzzler<\/a>.  I solved it the hard way, because I did not know any of the fancy math that the people in the comments section mentioned.  I will leave the closed form solution to them and the cited references.\r\n\r\nThe monte carlo solution that I came up with gave a great opportunity for code optimization via the profiler.  Here is a six minute video that shows the four iterations my code took.  I ended up restructuring so that I did not have clarifying &#8220;do nothing&#8221; code.  I got rid of a clarifying subfunction, and I stopped keeping track of all the iterations, and just stored the final result in an accumulator.\r\n\r\nThese optimizations cut the execution time by a factor of ten.\r\n\r\n<div><div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"3877437996001\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<div class=\"thumbnail thumbnail_asset asset_overlay video\"><a href=\"https:\/\/blogs.mathworks.com\/videos\/2009\/04\/17\/speeding-up-dougs-solution-with-the-profiler\/?dir=autoplay\"><img decoding=\"async\" src=\"https:\/\/cf-images.us-east-1.prod.boltdns.net\/v1\/static\/62009828001\/5eeb1aab-771c-4f0d-b5ef-b3d2f67c024e\/aec4b27d-8c38-4852-af04-9b302449612a\/1280x720\/match\/image.jpg\" onError=\"this.style.display ='none';\"\/>\n      <div class=\"overlay_container\">\n      <span class=\"icon-video icon_color_null\"><time class=\"video_length\">6:18<\/time><\/span>\n      <\/div>\n      <\/a><\/div><p>Last week, I posed a Puzzler.  I solved it the hard way, because I did not know any of the fancy math that the people in the comments section mentioned.  I will leave the closed form solution to them&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2009\/04\/17\/speeding-up-dougs-solution-with-the-profiler\/\">read more >><\/a><\/p>","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,12,10],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/366"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}