I was working with rbbox on my Matlab GUI application to create squares that marked important stuff inside an image. I recently needed to move away from the rectangle based approach to a polygon based approach. This meant not using rbbox. I found cool im* commands that did what I needed. These commands include imrect, impoly and imfreehand.
Today I pretty much finished the coding of the new version (with some little issues to resolve). When I did my final tests, I noticed that the new version lagged just a little when doing annotation actions (creating, moving, deleting…). I took this a bit further and did a very simple “top” based test to compare two versions of the GUI. The first version is the current one that implements the annotations with im* commands. And the other version is the one that I replaced that used the rbbox command.
In the figure, red line means the execution with the rm* functions, blue means rbbox. Notice that at the begining there is a spike that is comparable in the two cases. This is the GUI initialization.
In both lines there is a second spike that represents the start of a rectangle creation. Notice that the imrect (red) command uses 100% of one of my CPUs while the rbbox uses 50% approx.
After I created the rectangle I stretched it a bit before finalizing the tests. Notice that the stretch action in the imrect line (red) is eating at my CPU. It has a second spike that reaches close to 100%. While the rbbox line (blue) has a milder footprint and does not go past 50%.
So: What is imrect doing that eats up most of my CPU? I have no idea :(. But it’s annoying. One explanation could be the extra functionality that im* functions bring to the GUI. But given the performance of rbbox, I’m left with the impression that it could be done better.