lundi 30 novembre 2015

Lambda construction performance and static lambda?

Consider the following code:

// Classic version
template <class It>
It f(It first, It last)
{
    using value_type = It::value_type;
    auto lambda = [](value_type x){return x > 10 && x < 100;};
    return std::find_if(first, last, lambda);
}

// Static version
template <class It>
It f(It first, It last)
{
    using value_type = It::value_type;
    static auto lambda = [](value_type x){return x > 10 && x < 100;};
    return std::find_if(first, last, lambda);
}

Is there any performance difference between the two? What's the construction time of a lambda function? Is the static version better in terms of performances because the lambda is constructed only once?

Aucun commentaire:

Enregistrer un commentaire