Built-in "filter" function works drastically faster in Matlab than in generated C code
Show older comments
Hello everyone.
I have an algorithm using "filter" function. We are testing generated to C version of it and the main bottleneck (around 50% of whole time) spent is C code related to processing of this "filter" call, and function inside which this call located take like 66%. But profile of this function in Matlab tells completely different story, even line in which "filter" called is not the most time consuming inside function calling it but like top 3. And function calling "filter" is just like top 10 in profiling only (like 4-5% instead of 66%). Unfortunately "filter" is built-in function of Matlab so I can't profile it "more" in Matlab to really understand the issue. What can cause such behavior?
I was trying to run matlab in single-thread mode and played with optimizations for code generation and compiler flags but it doesn't change overall picture of "bottleneck".
Answers (1)
That filter becomes the bottleneck can have two reasons:
- filter is processed less efficiently in the generated C code.
- The efficiency of filter does not change, but the rest of the code is processed much faster.
2 Comments
Jakub Jon
on 24 Sep 2021
Jan
on 26 Sep 2021
You find a slightly faster C implementation of FILTER here: https://www.mathworks.com/matlabcentral/fileexchange/32261-filterm . Currently Matlab is still faster if multithreading is used.
I've improved the code to consider cheaper computations of FIR filters. The multi-threading is not working yet, so it will take some time until I publish it.
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!