Matlab profiler

A really useful tool for code optimization in Matlab is the profiler. Using the profiler we can find the really computational intensive parts of our model and by trying to optimize them we can reduce heavily the computation time of the simulation. We can find the profiler on the desktop –> profiler (as seen below):

matlab_profiler01

Once opened we can run any code we want through the profiler from the “Run this code:’” bar as seen below. I run a script of my own called prediction_script.

matlab_profiler02

Once the code is ran we get a detailed report of how much time each function we use is called and how many times it is called throughout the simulation.

matlab_profiler03

In the above picture we can see that the total time of the predictor script is 52.865 seconds. However only 0.031 seconds are used to run the code in the predictor script (this is the self time). so in my case the prediction script calls the predictor twice. and the predictor calls any other function.

The most computational intensive function in my case is the get_value which is called 739180 times and lasts for 18.697 seconds. It does not call any other function (both the total and the self time are the same).

By clicking on the get_value we get the detailed information on where the most computations are done. By using the profiler often we get to know which operations are time consuming in Matlab and end up writing better code.

matlab_profiler04

As we can get information on which functions call the selected function the profiler can also be used for reverse engineering in case of unknown code.

So if I get to make the get_value function faster or I manage to call it less times then the simulation will end up faster overall. Easy as pie. A really useful tool!

MatLab to Excel

Sometimes I have trouble visualizing some matrix structures that I create in MatLab. And when I get to see them in the MatLab command line or the matlab workspace it does not help much. A way to deal with that and seek and understand patterns easier is to export them in excel. MatLab supports this with the instructions:

xlsread (to read from an excel file) and

xlswrite (to write to one)

the parameters that follow are:

(filename, matrix(to be written max 2 dimensions), sheet, range)

by using the following one can create matrixes that contain both data and titles:

matrix1 = {‘Title1', Title2'; 1 423 ; 2 742; 3 192}

And to actually write in an excel file:

xlswrite('matrix1.xls', matrix1, 'Example Sheet', 'E1')

It is needless to point out the usefulness of this. One can either import data to MatLab from an excel (which amy be automated to produce desired data and easily editable) and once the simulation is done and the results are calculated they can be exported for further analysis in an excel too.

Both tools are very powerful mathematical tools each one with different properties. The combination of these both can really give solutions to many problems!

Benchmarking and statistics

Well I’m pretty sure that most of you out there like to compare hardware. The hardware you have, the hardware you will get, the hardware you had, the one your friends have, the neighbor’s and so on. The problem is that it is not easy to compare them if we don’t benchmark them. So, Passmark is a site that one can compare his CPU and GPU to any other CPU and GPU simply by searching for it! Or if you want to see how the new hardware racks up you can just visit the equivalent list.

I think that they offer a free 30days trial of their benchmarking tool as well if you want to check how you rig is doing. They also have a list of user benchmark (the 20 best and the 20 worst).

Apart from hardware other interesting statistics is operating system usage, browsers and so on. The classic flame wars that pop up in forums. Net Market Share offers real time data of the internet usage. ISPs , resolutions, operating systems, browsers, anything a curious guy wants to know. I found out this site when I was checking out that this August Windows Vista market share went lower than that of Windows 7. However Windows XP is still high.

So that’s enough to lose a couple of hours measuring stuff. I know you like it!