memesearch
C++17 String Sorting Trap

C++17 String Sorting Trap

Download Find similar pictures
Text on the meme
C++17: Effective (Sub-)String Sorting std::vector<std::string> coll; coll.reserve(numElems); for (int i=0; i < numElems / 2; ++i) { coll.emplace_back("id" + std::to_string(i)); coll.emplace_back("ID" + std::to_string(i)); } sort(std::execution::par, coll.begin(), coll.end()); sort(std::execution::par, coll.begin(), coll.end(), [](const auto& a, const auto& b) { return a.substr(2) < b.substr(2); }); sort(std::execution::par, coll.begin(), coll.end(), [](const auto& a, const auto& b) { return std::string_view(a).substr(2) < std::string_view(b).substr(2); }); id0 ID0 id1 ID1 ... id99 ID99 id100 ID100 ... sort() numElems seq par 100,000 22.0 9.5 1,000,000 256.7 110.7 substring 100,000 52.3 23.5 1,000,000 879.1 281.9 stringview 100,000 18.1 8.1 1,000,000 249.8 95.9 69 C++17 | josuttis.com
What it means

A photographed presentation slide compares three ways to sort strings in C++17: ordinary sorting, sorting by temporary substrings, and sorting with string_view. The joke is that a small-looking optimization using string_view is much faster and avoids the performance trap of repeatedly creating substrings, especially on large datasets. EN: A photographed presentation slide compares three ways to sort strings in C++17: ordinary sorting, sorting by temporary substrings, and sorting with string_view. The joke is that a small-looking optimization using string_view is much faster and avoids the performance trap of repeatedly creating substrings, especially on large datasets.

Objects
Tags
Source
Type
image
Size
800×589 · 50.0 KiB
Mood
technical, ironic
Language
en
Added