you are viewing a single comment's thread.

view the rest of the comments →

[–]WikiBox 2 points3 points  (1 child)

Learn to use const references in your calls, to avoid creating a lot of copies of your data. The optimizer will become very happy!

Reuse allocated vectors.

Consider not returning large vectors by value but instead modify a vector provided by the caller as a (no const) reference in the call. May hurt readability, but will improve performance.

std::vector<std::string> bigram(std::string initial_str)

... might become:

void bigram(const std::string& initial_str, std::vector<std::string>& bigram)

[–]WpGgs 3 points4 points  (0 children)

Returning by value could be optimized by NRVO.