Fast way to apply function on each element in vector

Hello,
some time ago I discovered great FloatVectorOperations and I fell in love with it :slight_smile:

And lastly I got into situation that for each element in the array I need to calculate std::log10() and store those values in the same array, or at least copy them to another array.

Now I use basic for loop iterating through each element in the array and calculate std::log10() but I wonder if is there any better and faster way to do that?

I tried something like:

std::for_each(p, p+sizeOfArray, [](float &n) { n = std::log10(n); });

Where p is of course pointer to the first element of float array.

I have not made any extensive tests on very big arrays, but for my needs it looks like std::for_each is not much faster than iterating through each elements with standard for loop. While FloatVectorOperations makes really big difference in comparison with for loop.

So I would like to ask you if you know any better solution than classic for loop or std::for_each() ?

For any help great thanks in advance.

Best Regards

1 Like

Apple vDSP and Intel IPP both provide SIMD-accelerated log10 functions. You can write some code to call either vDSP or IPP, depending on the platform, in much the same way that juce FloatVectorOperarions is implemented

1 Like

Hello,
thanks, actually in vDSP I canโ€™t find method which provides calculating exactly log10 function on vectors, but I found out method which converts vectors to decibels, and internal it uses log10. Itโ€™s enough for me, thanks. But if you know functions which calculates log10 then please let me know.

This is giving me low to mid single-digit percentage reductions in CPU usage across several of my compressor plugins on PC - not bad for a small amount of work! Thank you.