Is there a faster version of min
Afficher commentaires plus anciens
I did the profiling, and this line takes the most of time: running 28449740 times and takes 163.84s.
I am wonderring if there is any version that is faster than min.
[a,b]=min(c(s1,s2));
9 commentaires
KSSV
le 27 Avr 2018
What is s1 and s2? What exactly you are trying to do? Show us the code.....min is actually very efficient.
Chaoyang Jiang
le 27 Avr 2018
Ameer Hamza
le 27 Avr 2018
min is already optimal. The code is slow because you are running for loop 41857887 time and not changing anything inside. Your code is equivalent even if you remove for. Do this
c=1:8760;
d=5123:5146;
tic
[a,b]=min(c(1,d));
toc
Chaoyang Jiang
le 27 Avr 2018
Modifié(e) : Chaoyang Jiang
le 27 Avr 2018
KSSV
le 27 Avr 2018
You replace/ use the updates values......you need not to run a loop.
Ameer Hamza
le 27 Avr 2018
@Chaoyang then you will need to show the code, maybe there are some other ways to make it faster. As far is min is concerned it can't be further optimized.
Walter Roberson
le 27 Avr 2018
If you break out the timing, you will likely find that the cost is in extracting the sub-array c(1,d) to send to the min() function. min() is at worst a linear operation (I say at worst because in theory it could be run in parallel for sufficiently large arrays.)
Stephen23
le 27 Avr 2018
"... this line takes the most of time: running 28449740 times and takes 163.84s."
Sure. But there are several operations on that line, so how do you know that min is the slow one?
Walter Roberson
le 27 Avr 2018
Reminder: extracting consecutive rows is faster than extracting consecutive columns, so you should consider transposing your array.
Réponses (0)
Catégories
En savoir plus sur Surrogate Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!