# Numerical Effects on Execution Time: Different Times for Different Data

Level 1
Level 1

Hello, I currently benchmark a linear support vector machine on the PSOC63. I trained the model offline and stored the model coefficients directly in the C code. Now I examined the follwing behaviour:

When executing the prediction on the PSOC I can record different execution times for different model data (but still same dimensions). The differences are about 2% of the execution time.

How is this possible? Are there any numerical effects that are important?

1 Solution

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Employee
Employee

I think it comes to how the compiler generates the assembly code to handle double precision point operations. The CPU only supports single floating-point operations, so it needs to combine multiple instructions to operate at double precision, which might take in consideration the number's signal.

7 Replies

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Moderator
Moderator

Hi @Berni27,

Could you let us know the following:

• What is the model data that is being worked on? Could you specify finer details such as dimensions, etc?
• What kind of testing is being performed?

Could you share the project so that analyzing the same would be easier?

Best regards,
Nikhil

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Level 1
Level 1

Hi @ncbs , thanks for the quick answer.
I use a linear binary SVM with 500 feautres. Data is stored using 2 double arrays with 500 values each (one for the coefficients of the SVM, one for the data/features to perform the prediction on). Furthermore, there is one double values that represents the bias.
I measure the execution time of the SVM prediction, which baisically is just this code snippet:

for (i = 0, l = current_features; i < l; i++) {
prob += coefficients[i] * *(features+i);
//printf("i:%d\n", i);
}
if (prob + intercepts > 0) {
label = 1;
}
else label = 0;

The behaviour I can measure is that as soon as I change the data and coefficients to other values, then the execution time changes. I do not understand why as always the same mathematical operations are involved.

Kind regards,

Bernhard

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Employee
Employee

Can you try to disable the compiler optimization? Perhaps the compiler some how is able to optimize the code based on a given set of coefficients/bias.

If you are still seeing a difference, would you mind to share the project?

Attachments are accessible only for community members.

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Level 1
Level 1

Hello,

I didn use any compiler optimization. I attached my project below.

The only thing I changed it the lines 16-21 and lines 45-50 to include or exclude the different datasets.

Thanks again.

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Employee
Employee

It seems the double operation execution time is affected when dealing with negative numbers. By simply changing the equation:

prob += coefficients[i] * *(features+i);

to

prob -= coefficients[i] * *(features+i);

You would get a different execution time.

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Level 1
Level 1

@RodolfoGL thank you very much for your answer. Is there any explanation why operations with negative numbers are handeled differently?

# Re: Numerical Effects on Execution Time: Different Times for Different Data

Employee
Employee

I think it comes to how the compiler generates the assembly code to handle double precision point operations. The CPU only supports single floating-point operations, so it needs to combine multiple instructions to operate at double precision, which might take in consideration the number's signal.