# why estimating 3 values takes longer time than estimating 4 values?

2 views (last 30 days)

Show older comments

##### 3 Comments

### Accepted Answer

Anton Kogios
on 14 Feb 2023

I am not exactly an 'expert', but the times I get depend on:

- the order that you run them (like 3, then 2, then 1). From my basic understanding, you get different results based on the order due to how things run on processors (I think?).
- more probably, the mean of u. I am not exactly sure about the aim of your code/what it is doing, but values of u with an even number of elements and a mean of 0 perform faster than values of u with one less element and a mean not equal to 0.

I modified your original main1TimeComparing.m to a new one (attached to post). It loops 20 times per length of u and also tests lengths of 5 and 6. I got the following results after running it twice on a M1 Pro MacBook Pro with the R2022b Apple Silicon Beta:

- Run 1: [5.3750 6.1739 6.0049 6.6926 6.3277]
- Run 2: [5.4516 6.2095 6.0587 6.7427 6.3106]

Hope this points you in the right direction since you know what your code is doing! In-built MATLAB functions have a lot of optimisations for vectors, and this may be a product of that.

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!