Performance using temporary boolean filter

조회 수: 4 (최근 30일)
mutt
mutt 2013년 2월 5일
In a situation where I need to use a logical filter (simply a vector of logical) 3 times in succession, am I likely to get a performance improvement by creating a temporary variable to hold the filter and then referring to that where necessary as opposed to just repeating the filter expression explicitly? e.g. I could define say: filter=(floor(x)==y); then do something to A(filter), B(filter) and C(filter) or I could do something to A(floor(x)==y), B(floor(x)==y) and C(floor(x)==y)

채택된 답변

Jan
Jan 2013년 2월 5일
A(floor(x)==y) creates the temporary array floor(x)==y explicitly. Therefore doing this three times needs more resources than making the comparison once only. Therefore A(filter) etc. is faster.

추가 답변 (1개)

Ryan Livingston
Ryan Livingston 2013년 2월 5일
The performance depends on many things. But it is likely that assigning filter will decrease the number of operations needed to be performed. Namely,
floor(x)==y
will only be calculated once.
Try both examples and run your code through the profiler to see how it affects things:

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by