I am developing a program in c#, and thanks to the matlab .net builder, I am using a matlab mapping toolbox function "polybool", which in one of it's options calculate the difference of 2 polygons in 2-D. The problem is that the functions takes about 0.01 seconds to finish in which is bad for me because I call it a lot. And this doesn't make sense at all because the polygons are 5 points each, so there is no way that it take 0.01 second to find the results. Does anyone has any ideas?
-
"tic; code; toc" is your friendBen Voigt– Ben Voigt2010-03-07 18:46:40 +00:00Commented Mar 7, 2010 at 18:46
-
Measuring timing can be a bit tricky, especially when the function does not take a lot of time to evaluate. I suggest you use timeit (mathworks.com/matlabcentral/fileexchange/18798) instead of tic/toc to check.Jonas– Jonas2010-03-07 19:08:22 +00:00Commented Mar 7, 2010 at 19:08
Add a comment
|
1 Answer
How are you computing the 0.01 seconds? If this is total operational time, it may very well be the marshaling in and out of the toolbox functionality, which will take some time. The actual routine may be running quickly, but getting your data from C# into the routine, and the results back, will have some overhead involved with the process.
Granted, this overhead probably scales well - since it's most likely (mostly) constant, so if you start dealing with larger polygons, you'll probably see your overall efficiencies scale very well.
1 Comment
Ben Voigt
Right, but large numbers of polygons might not. If polybool executes fast when called from Matlab and slow when called from C#, I'd start looking for a C# or C++ implementation.