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 and the cited references.
The 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 “do nothing” 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.
These optimizations cut the execution time by a factor of ten.
Doug,
I was somewhat surprised that there was such a significant overhead to calling a one-liner function. Is this a general feature? Can I speed up my code by simply by replacing every instance of pi with 3.14? Or did I misunderstand something in the video?
Thanks
This is weird. The video I saw on your blog home page is different from the one on the comment page. Maybe you wish to find the reason.
I initially saw the video on the blog home page and found it was not as you described in the blog, hence just left until I saw some comments there. In order to read these comments, I went into the comment page, then found the actual video is there.
This viedoe raised a user interface question for me:
If I profile my scripts from within the profiler and not from the commandline, how can I set profiling options, like what clock to use, weather to clock built-ins, and so on? I found no such menu options just now.
Weird, I just checked the main blog and the permalink. They were both the proper video. Please send me your system information via e-mail. Try and clear your cache before trying it again though. I would like to clear this up.
The User Interface that I used does not have access to all the functionality that the command line does. It is easy to use and fits what most people want when they profile.
Doug,
I was somewhat surprised that there was such a significant overhead to calling a one-liner function. Is this a general feature? Can I speed up my code by simply by replacing every instance of pi with 3.14? Or did I misunderstand something in the video?
Thanks
Naor,
One of the things to consider is that in this case, the function was called 500000 times for a total of 1.7 seconds or
>> 1.7/500000
ans =
3.4000e-006
So, the over head is minuscule, tiny, nothing. But that small amount of overhead times half a million? Well, now it is a noticeable delay.
This is an extreme case. I would not worry about it normally.
-doug
Doug
This is weird. The video I saw on your blog home page is different from the one on the comment page. Maybe you wish to find the reason.
I initially saw the video on the blog home page and found it was not as you described in the blog, hence just left until I saw some comments there. In order to read these comments, I went into the comment page, then found the actual video is there.
Yi
This viedoe raised a user interface question for me:
If I profile my scripts from within the profiler and not from the commandline, how can I set profiling options, like what clock to use, weather to clock built-ins, and so on? I found no such menu options just now.
Sincerely
Daniel Armyr
Yi,
Weird, I just checked the main blog and the permalink. They were both the proper video. Please send me your system information via e-mail. Try and clear your cache before trying it again though. I would like to clear this up.
Thanks,
Doug
@daniel,
The User Interface that I used does not have access to all the functionality that the command line does. It is easy to use and fits what most people want when they profile.
Doug
Hi Doug,
very useful video. Can you pls provide some video tutorial for simulink profiler.
Baskaran,
You would have to look to Seth:
http://blogs.mathworks.com/seth
I only do MATLAB.
Doug