Scilab's filter, for short coefficient vectors, function implements a linear convolution in C code; that alone, since there's no python to actually be evaluated here, just multiplication and addition, is much much faster than writing something in a scripting language that can't 100% be just-in-time compiled.
For longer vectors, scilab implements fast convolution; ie. it exploits the fact that (circular) convolution in time domain corresponds to point-wise multiplication in (discrete) frequency domain, and uses zero-padding and saving of overlaps to emulate the linear convolution (which filtering represents) with that.
So, either way, use your libraries when doing signal processing! Aside from the convolution, there's other things that are generally faster if done via clever usage of library functionality: For example, whenever you have a loop that looks like
sum = 0
for a, b in zip(vectorA, vectorB):
sum += a*b
you'd be far, far better of doing a dot product of the two vectors.
You have to consider this: Your CPU is very fast at doing basic math operations – often, it can do for example 8 multiply-and-accumulates (MAC) operations in a single step. Compared to that, parsing the structure of the (precompiled, even)
for loop, building temporary python objects to hold the individual values for
b, and overwriting the
sum object, thus removing the old object and replacing it with a new one, leading to garbage collection and so on, is way way way way more work than just doing the maths. I like to put it like this:
Imagine you're tasked with multiplying a lot of numbers between 0 and 10, but the numbers you need to multiply are written in text form in a book.
Reading that book will take much, much longer than the multiplications
That's how it is to use dynamic languages to do basic math operations.