filter function - delay at the first run
显示 更早的评论
Hi all, I have a question related to the filter function. I noticed a delay the first time this function is called for instance in a for loop.
Let's start from this code:
function y = dummy(x)
y = zeros(size(x));
[b, a] = cheby1(4, 0.5, 0.1);
for i = 1:size(x, 2)
tic
y(:, i) = filter(b, a, x(:, i));
toc
end
end
with x = rand(10000, 64);
Every time the function dummy is called, the computational time at the first iteration (i==1) is higher (e.g. ~50 ms in my workstation).
Do you any idea why it happens? There is a way to avoid it?
Thanks
Luca
回答(2 个)
Sean de Wolski
2012-4-23
That is likely the JIT compiler taking a little extra time on the first iteration but then being much slower.
What does the timing look like if you turn the JIT off?
feature accel off
Jan
2012-4-23
In the line:
y(:, i) = filter(b, a, x(:, i));
memory is reserved for x(:,1). Perhaps this memory is reused later by the smart JIT? This is a pure guessing.
Just for curiosity: Do you know that the loop over i is not necessary and that:
y = filter(b, a, x)
would use all cores for multi-threading, because x has more than 16 columns?
类别
在 帮助中心 和 File Exchange 中查找有关 Digital Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!