다음 함수를 호출하면 개발중인 프로그램이 3 배 느려집니다. 몇 백만 번이라도 불리지 않는다면 나쁘지 않을 것입니다.max_element & iterator = 3x slower 인 C++ 함수
double obterNormLarguraBanda(const std::vector<double>& v, int periodos)
{
int aa;
double maximo, minimo, valor;
std::vector<double>::const_iterator inicio;
if (v.size() < periodos)
{
inicio = v.begin();
}
else
{
inicio = v.end() - periodos;
}
maximo = *max_element(inicio, v.end(), excludeWrong);
minimo = *min_element(inicio, v.end(), excludeWrong);
return (v.back()-minimo)/(maximo - minimo);
}
bool excludeWrong(double i, double j)
{
if (i==-1 || j==-1) return false;
return i<j;
}
periodos
이 기능을 속도를 크게하는 또 다른 방법이 있나요 값 500 소요?
루이스는
디버그 모드로 컴파일하고 있습니까? 아마도 그것은 안전한 stl 스타일 구현을 사용하고 있으며 호출은 매번 검사되고 있습니다. 최적화를 사용하도록 설정하세요. –
'min_element'와'max_element' 없이는 더 잘할 수있을 것입니다. –
엄격한 평등을 위해'double'을'-1'과 비교하는 것은 아주 좋은 생각입니다. – sharptooth