samedi 31 mars 2018

How to optimize getting maximum values in array?

There is a function which is getting maximum values of each period-length interval in array.

void f(const std::vector<double> &v, std::vector<double> &vv, size_t period)
{
    vv.resize(v.size());

    for (size_t i = period; i < v.size() + 1; ++i) {
        vv[i - 1] = *std::max_element(v.begin() + i - period, v.begin() + i);
    }
}

How can I optimize this function by performance?

Aucun commentaire:

Enregistrer un commentaire