Azzera filtri
Azzera filtri

speed up the & operation

2 visualizzazioni (ultimi 30 giorni)
Chaoyang Jiang
Chaoyang Jiang il 12 Apr 2018
Commentato: Walter Roberson il 13 Apr 2018
How to speed up the following code? I did profiling, and this line takes 3267.72s for calling 245913489 times.
a=[1 0 1 1 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1];
b=[1 0 1 1 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0];
for i=1:1000000
aat=((a(1,1:24)==0)&(b(1,25:48)==1)&(~ismembc(1:24,5:50)))';
end
  5 Commenti
Chaoyang Jiang
Chaoyang Jiang il 13 Apr 2018
ismembc seems to be faster than ismember, that is why I used this function.
Walter Roberson
Walter Roberson il 13 Apr 2018
for i=1:1000000
part1 = a(1,1:24)==0;
part2 = b(1,25:48)==1;
part3 = ~ismembc(1:24,5:50);
part4 = part1 & part2 & part3;
aat = part4 .';
end
Now when you profile you can see exactly which part of the expression is taking the most time.
We suspect that it is the ismembc() that is taking all of the time and that the & is relatively fast.

Accedi per commentare.

Risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by