The class template basic_string_view describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero.
intmain() { constexprauto s = "it is a test"sv; auto s1 = "it is a test"sv; constchar * cc = "it is a test"; string_view s2(cc, 12); auto str = "it is a test"s; const string str1 = "it is a test"; string_view s3(&str[0], str.size()); string_view s4(&str1[0], str1.size()); auto s5 = "it is a test"sv; constauto s6 = "it is a test"sv; constexprint LEN = 1000000;
chrono::steady_clock::time_point st1 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { constexprauto st = s.substr(3); } chrono::steady_clock::time_point ed1 = chrono::steady_clock::now();
chrono::steady_clock::time_point st2 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { auto st = s1.substr(3); } chrono::steady_clock::time_point ed2 = chrono::steady_clock::now();
chrono::steady_clock::time_point st3 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { auto st = str.substr(3); } chrono::steady_clock::time_point ed3 = chrono::steady_clock::now();
chrono::steady_clock::time_point st4 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { constauto st = str1.substr(3); } chrono::steady_clock::time_point ed4 = chrono::steady_clock::now();
chrono::steady_clock::time_point st5 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { auto st = s2.substr(3); } chrono::steady_clock::time_point ed5 = chrono::steady_clock::now();
chrono::steady_clock::time_point st6 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { auto st = s3.substr(3); } chrono::steady_clock::time_point ed6 = chrono::steady_clock::now();
chrono::steady_clock::time_point st7 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { auto st = s4.substr(3); } chrono::steady_clock::time_point ed7 = chrono::steady_clock::now();
chrono::steady_clock::time_point st8 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { auto st = s5.substr(3); } chrono::steady_clock::time_point ed8 = chrono::steady_clock::now();
chrono::steady_clock::time_point st9 = chrono::steady_clock::now(); for (int i = 0; i < LEN; i++) { constauto st = s6.substr(3); } chrono::steady_clock::time_point ed9 = chrono::steady_clock::now();
constexpr sv time 0us. sv time 0us. s time 9036us. const s time 9478us. sv-char time 0us. sv-s time 563us. sv-const s s time 543us. sv time 0us. const sv time 0us.