Copy vs Move Semantics: std::string Performance

Question 11 / 12 Correct so far: 0 (0 answered)

Snippet A

String Copy

std::string processString(std::string data) {
    std::string result = data;
    result += " processed";
    return result;
}

std::string input = TEST_INPUT;
std::string output = processString(input);
Snippet B

String Move

std::string processString(std::string data) {
    std::string result = std::move(data);
    result += " processed";
    return result;
}

std::string input = TEST_INPUT;
std::string output = processString(std::move(input));
Shared test data (shared-setup)
const std::string TEST_INPUT = "Hello, World! This is a test string with some content.";

Which snippet is faster?

Select the correct answer(s)