Skip to main content
Visitor II
October 15, 2024
Question

Getting more execution time when using arm_math.h then math.h?

  • October 15, 2024
  • 1 reply
  • 613 views

Hello, 

I have created one function to calculate mean of 20 samples of float and run it using math.h and another function using arm_math mean function and check the execution time by making GPIO on and off. I am getting more exeution time for arm math function when compare to normal mean calculation.Why?

Below is the code I am using to check the execution time. I have set the optimization to O2.

 

 

 

 

//arm math function 
float arm_mean (const float x[768])
{
 volatile float32_t offset_mean;
 arm_mean_f32(x, 20, &offset_mean);
 printf("%f\n",offset_mean);
 return offset_mean;
}
 
//math function
float mean( const float x[768])
{
 volatile float32_t offset_mean;
 float sum = 0.0;
 for(int i = 0; i < 20; i++)
 {
 sum += x[i];
 }
 // Calculate the mean offset
 offset_mean = sum / 20.0;
 printf("%f\n",offset_mean);
 return offset_mean;
}

int main(){
// Initializations
while(1){
	GPIO_OutSet(gpio_test_pin.port, gpio_test_pin.mask);
#if 1
	offset_mean = mean(input_array);
#else
 offset_mean = arm_mean(const float x[768])
#endif
	GPIO_OutClr(gpio_test_pin.port, gpio_test_pin.mask);
}
}

 

 

 

 

For arm_mean ,

--> 10 us ( for 20 samples)

--> 203 us( for 700 samples)

for mean

--> 5 us (for 20 samples)

--> 79 us( for 700 samples)

As per the study, the arm_math function takes less time when compare to math function. Correct me if wrong?

    This topic has been closed for replies.

    1 reply

    ST Employee
    October 23, 2024

    I do similar tests, without printf() in arm_mean()/mean().

    test with 200 elements:
    init float_array[200] as 1.0/2.0/3.0/... : optimization=None/Low/Medium/High(speed), 78/56/54/28 us
    calling mean(float_array): optimization=None/Low/Medium/High(speed), 26.4/72/27.2/28 us
    calling arm_mean(float_array): optimization=None/Low/Medium/High(speed), 26.4/20/19.2/18.8 us

    so, in general, arm_mean() is faster than mean() when float_array element is 200 or more.