{"id":350355,"date":"2023-07-17T15:01:37","date_gmt":"2023-07-17T15:01:37","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=350355"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=350355","title":{"rendered":"<span>\u041a\u0430\u043a \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0432 C++<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d. \u041d\u0435\u043c\u0443\u0434\u0440\u0435\u043d\u043e, \u0443 \u043f\u043b\u044f\u0448\u0443\u0449\u0438\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0431\u0443\u043a\u043e\u0432\u043e\u043a \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c\u044b\u0439 \u0448\u0430\u0440\u043c, \u0430 \u0444\u0430\u043a\u0442 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043c \u0435\u0449\u0435 \u0438 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0434\u043e\u0433\u0430\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043e.<\/p>\n<p>\u041d\u043e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e?<\/p>\n<h2>\u0421\u0442\u043e\u0439\u0442\u0435, \u0441\u0442\u043e\u0439\u0442\u0435, \u043d\u043e \u0443 \u043d\u0430\u0441 \u0432\u0435\u0434\u044c \u0432\u0441\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c<\/h2>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0435\u0441\u043b\u0438 \u043c\u044b \u0436\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0432 C++20 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c: \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e<em> \u0440\u0430\u0441\u043e\u0432\u043e \u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (<\/em><code>std::cout<\/code><em> \u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f)<\/em>, <em>\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e C API \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 (<\/em><code>std::printf<\/code><em> \u0438 \u0435\u0433\u043e \u0431\u0440\u0430\u0442\u044c\u044f), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <\/em><code>std::format<\/code><em> \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <\/em><code>std::fputs<\/code><em>. <\/em>\u041d\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0441\u0432\u043e\u0438\u043c\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">std::cout &lt;&lt; \"The answer is \" &lt;&lt; 42 &lt;&lt; \".\\n\";<\/code><\/pre>\n<p>\u0414\u0430\u0436\u0435 \u0441 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432 \u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435, \u0447\u0442\u043e \u0432\u044b\u0440\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043b\u043e\u043a\u0430\u043b\u044f\u043c\u0438, \u0434\u0430\u0436\u0435 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043d\u0430\u043c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b:<\/p>\n<pre><code class=\"assembly\">  push rbx   mov rbx, qword ptr [rip + std::cout@GOTPCREL]   lea rsi, [rip + .L.str.1]   mov edx, 14   mov rdi, rbx   call std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)@PLT   mov rdi, rbx   mov esi, 42   call std::basic_ostream&lt;char, std::char_traits&lt;char> >::operator&lt;&lt;(int)@PLT   lea rsi, [rip + .L.str.2]   mov edx, 2   mov rdi, rax   pop rbx   jmp std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)@PLT<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>std::printf<\/code><em>:<\/em><\/p>\n<pre><code class=\"cpp\">std::printf(\"The answer is %d.\\n\", 42);<\/code><\/pre>\n<pre><code class=\"assembly\">  lea rdi, [rip + .L.str]   mov esi, 42   xor eax, eax   jmp printf@PLT<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0432\u0441\u0435 \u0442\u0430\u043a \u0436\u0435 \u0431\u0435\u0437\u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043b\u043e\u043a\u0430\u043b\u0438 \u0438, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043b\u043e\u0445\u043e \u0434\u0440\u0443\u0436\u0438\u0442 \u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u0441, \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">void greet(std::string_view name) {   std::printf(\"Hello, %s!\", name.data()); }<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a <em>\u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e, <\/em>\u0442\u0430\u043a \u043a\u0430\u043a <code>%s<\/code> \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0443\u043b\u044c-\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0447\u0435\u0440\u0435\u0437 <code>std::string_view<\/code>, \u043d\u0443\u043b\u044c-\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0431\u044b\u0442\u044c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u043d\u0430.<\/p>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439:<\/p>\n<pre><code class=\"cpp\">auto msg = std::format(\"The answer is {}.\\n\", 42); std::fputs(msg.c_str(), stdout);<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0443\u0447\u0438 \u043b\u0438\u0448\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043a\u0430\u043a \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u0430\u043a \u0438 <code>std::printf<\/code>, \u043e\u043d \u0432\u0441\u0435 \u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442 \u043d\u0435 \u043d\u0443\u0436\u043d\u0443\u044e \u043d\u0430\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code>c_str<\/code> \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 <em>I\/O \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/em>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0431\u0443\u0434\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0433\u043e\u0432\u043e\u0440\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438, \u043c\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0438\u0437 \u0432\u0438\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <em>Unicode<\/em> \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"cpp\">std::cout &lt;&lt; \"\u041f\u0440\u0438\u0432\u0435\u0442, \u03ba\u03cc\u03c3\u03bc\u03bf\u03c2!\";<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 Linux \u0438 MacOS \u0441\u0438\u0441\u0442\u0435\u043c \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043e\u0442 \u043d\u0435\u0433\u043e \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0442\u043e \u043d\u0430 Windows \u043c\u044b \u043e\u0431\u0440\u0435\u0447\u0435\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043a\u0440\u0430\u043a\u043e\u0437\u044f\u0431\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <code>\u2568\u0192\u2564\u00c7\u2568\u2555\u2568\u2593\u2568\u2561\u2564\u00e9, \u256c\u2551\u2567\u00ee\u2567\u00e2\u256c\u255d\u256c\u2510\u2567\u00e9!<\/code>, \u043a\u0430\u043a \u0431\u044b \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0444\u043b\u0430\u0433\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0435, \u043d\u0435\u0443\u0436\u0435\u043b\u0438 \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043b\u044e\u0441\u0430\u0445 \u043d\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 (Linux, MacOS, Windows) \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e? \u0414\u0430\u0436\u0435 <em>Python<\/em> \u0442\u0430\u043a \u043c\u043e\u0436\u0435\u0442, \u0430 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c?<\/p>\n<h2>\u0421\u043f\u0435\u0448\u0443 \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c, \u0441 C++23  \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c Python<\/h2>\n<p>\u0412\u0435\u0434\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <code>std::print<\/code>, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u0440\u0443\u0436\u0430\u0449\u0438\u0439 \u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u043b\u044e\u0441\u0430\u043c\u0438, \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439, \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0439 <em>UTF-8<\/em> \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043d\u0430 \u0432\u0441\u0435\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0445, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439, \u0447\u0435\u043c <code>std::printf<\/code>:<\/p>\n<pre><code class=\"cpp\">std::print(\"The answer is {}\", 42);<\/code><\/pre>\n<pre><code class=\"assembly\">  sub rsp, 24   mov qword ptr [rsp], 42   lea rdi, [rip + .L.str]   mov rcx, rsp   mov esi, 18   mov edx, 1   call fmt::v10::vprint(fmt::v10::basic_string_view&lt;char>, fmt::v10::basic_format_args&lt;fmt::v10::basic_format_context&lt;fmt::v10::appender, char> >)@PLT   add rsp, 24   ret<\/code><\/pre>\n<p>\u0414\u0430, \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 <code>std::printf<\/code> \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>print<\/code>, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/fmtlib\/fmt\" rel=\"noopener noreferrer nofollow\">libfmt<\/a>, c <code>printf<\/code> \u0438 <code>ostream<\/code>:<\/p>\n<pre><code class=\"cpp\">#include &lt;cstdio> #include &lt;iostream>  #include &lt;benchmark\/benchmark.h> #include &lt;fmt\/ostream.h>  void printf(benchmark::State&amp; s) {   while (s.KeepRunning())     std::printf(\"The answer is %d.\\n\", 42); } BENCHMARK(printf);  void ostream(benchmark::State&amp; s) {   std::ios::sync_with_stdio(false);   while (s.KeepRunning())     std::cout &lt;&lt; \"The answer is \" &lt;&lt; 42 &lt;&lt; \".\\n\"; } BENCHMARK(ostream);  void print(benchmark::State&amp; s) {   while (s.KeepRunning())     fmt::print(\"The answer is {}.\\n\", 42); } BENCHMARK(print);  void print_cout(benchmark::State&amp; s) {   std::ios::sync_with_stdio(false);   while (s.KeepRunning())     fmt::print(std::cout, \"The answer is {}.\\n\", 42); } BENCHMARK(print_cout);  void print_cout_sync(benchmark::State&amp; s) {   std::ios::sync_with_stdio(true);   while (s.KeepRunning())     fmt::print(std::cout, \"The answer is {}.\\n\", 42); } BENCHMARK(print_cout_sync);  BENCHMARK_MAIN();<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>apple clang 11.0.0<\/em> c \u0444\u043b\u0430\u0433\u0430\u043c\u0438 <em>-O3 -DNDEBUG<\/em> \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0430 <em>MacOS 10.15.4 <\/em>\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code>Run on (8 X 2800 MHz CPU s) CPU Caches:   L1 Data 32K (x4)   L1 Instruction 32K (x4)   L2 Unified 262K (x4)   L3 Unified 8388K (x1) Load Average: 1.83, 1.88, 1.82 ----------------------------------------------------------- Benchmark                Time             CPU   Iterations ----------------------------------------------------------- printf                87.0 ns         86.9 ns      7834009 ostream                255 ns          255 ns      2746434 print                 78.4 ns         78.3 ns      9095989 print_cout            89.4 ns         89.4 ns      7702973 print_cout_sync       91.5 ns         91.4 ns      7903889<\/code><\/pre>\n<p><code>print<\/code> \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0434\u0435\u0440\u043e\u043c: \u043c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0438\u043c, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0442\u0430\u043a \u043e\u043d \u0435\u0449\u0435 \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u0432 <em>stdout <\/em>\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 14% \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c <em>printf (<\/em>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 \u0432 <em>stdout).<\/em><\/p>\n<p>\u041a\u0430\u043a \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0432 C++? <strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <\/strong><code>std::print<\/code><strong>!<\/strong><\/p>\n<details class=\"spoiler\">\n<summary>\u041d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0434\u0430, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0442 <em>Windows<\/em> \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0432\u0430\u043c \u0441\u043f\u0435\u0440\u0432\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <code>std::print<\/code> \u0432 <em>libc++ <\/em>\u0438 <em>libstdc++. <\/em>\u041f\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043d\u0430 <em>17.07.2023<\/em>, \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0438 \u0442\u0430\u043c, \u043d\u0438 \u0442\u0430\u043c.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u0430\u043c \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0436\u0434\u0430\u0442\u044c, \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/fmtlib\/fmt\" rel=\"noopener noreferrer nofollow\">fmtlib<\/a>.<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/748336\/\"> https:\/\/habr.com\/ru\/articles\/748336\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d. \u041d\u0435\u043c\u0443\u0434\u0440\u0435\u043d\u043e, \u0443 \u043f\u043b\u044f\u0448\u0443\u0449\u0438\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0431\u0443\u043a\u043e\u0432\u043e\u043a \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c\u044b\u0439 \u0448\u0430\u0440\u043c, \u0430 \u0444\u0430\u043a\u0442 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043c \u0435\u0449\u0435 \u0438 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0434\u043e\u0433\u0430\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043e.<\/p>\n<p>\u041d\u043e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e?<\/p>\n<h2>\u0421\u0442\u043e\u0439\u0442\u0435, \u0441\u0442\u043e\u0439\u0442\u0435, \u043d\u043e \u0443 \u043d\u0430\u0441 \u0432\u0435\u0434\u044c \u0432\u0441\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c<\/h2>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0435\u0441\u043b\u0438 \u043c\u044b \u0436\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0432 C++20 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c: \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e<em> \u0440\u0430\u0441\u043e\u0432\u043e \u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (<\/em><code>std::cout<\/code><em> \u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f)<\/em>, <em>\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e C API \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 (<\/em><code>std::printf<\/code><em> \u0438 \u0435\u0433\u043e \u0431\u0440\u0430\u0442\u044c\u044f), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <\/em><code>std::format<\/code><em> \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <\/em><code>std::fputs<\/code><em>. <\/em>\u041d\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0441\u0432\u043e\u0438\u043c\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">std::cout &lt;&lt; \"The answer is \" &lt;&lt; 42 &lt;&lt; \".\\n\";<\/code><\/pre>\n<p>\u0414\u0430\u0436\u0435 \u0441 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432 \u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435, \u0447\u0442\u043e \u0432\u044b\u0440\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043b\u043e\u043a\u0430\u043b\u044f\u043c\u0438, \u0434\u0430\u0436\u0435 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043d\u0430\u043c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b:<\/p>\n<pre><code class=\"assembly\">  push rbx   mov rbx, qword ptr [rip + std::cout@GOTPCREL]   lea rsi, [rip + .L.str.1]   mov edx, 14   mov rdi, rbx   call std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)@PLT   mov rdi, rbx   mov esi, 42   call std::basic_ostream&lt;char, std::char_traits&lt;char> >::operator&lt;&lt;(int)@PLT   lea rsi, [rip + .L.str.2]   mov edx, 2   mov rdi, rax   pop rbx   jmp std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)@PLT<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>std::printf<\/code><em>:<\/em><\/p>\n<pre><code class=\"cpp\">std::printf(\"The answer is %d.\\n\", 42);<\/code><\/pre>\n<pre><code class=\"assembly\">  lea rdi, [rip + .L.str]   mov esi, 42   xor eax, eax   jmp printf@PLT<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0432\u0441\u0435 \u0442\u0430\u043a \u0436\u0435 \u0431\u0435\u0437\u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043b\u043e\u043a\u0430\u043b\u0438 \u0438, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043b\u043e\u0445\u043e \u0434\u0440\u0443\u0436\u0438\u0442 \u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u0441, \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">void greet(std::string_view name) {   std::printf(\"Hello, %s!\", name.data()); }<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a <em>\u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e, <\/em>\u0442\u0430\u043a \u043a\u0430\u043a <code>%s<\/code> \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0443\u043b\u044c-\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0447\u0435\u0440\u0435\u0437 <code>std::string_view<\/code>, \u043d\u0443\u043b\u044c-\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0431\u044b\u0442\u044c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u043d\u0430.<\/p>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439:<\/p>\n<pre><code class=\"cpp\">auto msg = std::format(\"The answer is {}.\\n\", 42); std::fputs(msg.c_str(), stdout);<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0443\u0447\u0438 \u043b\u0438\u0448\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043a\u0430\u043a \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u0430\u043a \u0438 <code>std::printf<\/code>, \u043e\u043d \u0432\u0441\u0435 \u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442 \u043d\u0435 \u043d\u0443\u0436\u043d\u0443\u044e \u043d\u0430\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code>c_str<\/code> \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 <em>I\/O \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/em>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0431\u0443\u0434\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0433\u043e\u0432\u043e\u0440\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438, \u043c\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0438\u0437 \u0432\u0438\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <em>Unicode<\/em> \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"cpp\">std::cout &lt;&lt; \"\u041f\u0440\u0438\u0432\u0435\u0442, \u03ba\u03cc\u03c3\u03bc\u03bf\u03c2!\";<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 Linux \u0438 MacOS \u0441\u0438\u0441\u0442\u0435\u043c \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043e\u0442 \u043d\u0435\u0433\u043e \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0442\u043e \u043d\u0430 Windows \u043c\u044b \u043e\u0431\u0440\u0435\u0447\u0435\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043a\u0440\u0430\u043a\u043e\u0437\u044f\u0431\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <code>\u2568\u0192\u2564\u00c7\u2568\u2555\u2568\u2593\u2568\u2561\u2564\u00e9, \u256c\u2551\u2567\u00ee\u2567\u00e2\u256c\u255d\u256c\u2510\u2567\u00e9!<\/code>, \u043a\u0430\u043a \u0431\u044b \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0444\u043b\u0430\u0433\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0435, \u043d\u0435\u0443\u0436\u0435\u043b\u0438 \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043b\u044e\u0441\u0430\u0445 \u043d\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 (Linux, MacOS, Windows) \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e? \u0414\u0430\u0436\u0435 <em>Python<\/em> \u0442\u0430\u043a \u043c\u043e\u0436\u0435\u0442, \u0430 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c?<\/p>\n<h2>\u0421\u043f\u0435\u0448\u0443 \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c, \u0441 C++23  \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c Python<\/h2>\n<p>\u0412\u0435\u0434\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <code>std::print<\/code>, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u0440\u0443\u0436\u0430\u0449\u0438\u0439 \u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u043b\u044e\u0441\u0430\u043c\u0438, \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439, \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0439 <em>UTF-8<\/em> \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043d\u0430 \u0432\u0441\u0435\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0445, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439, \u0447\u0435\u043c <code>std::printf<\/code>:<\/p>\n<pre><code class=\"cpp\">std::print(\"The answer is {}\", 42);<\/code><\/pre>\n<pre><code class=\"assembly\">  sub rsp, 24   mov qword ptr [rsp], 42   lea rdi, [rip + .L.str]   mov rcx, rsp   mov esi, 18   mov edx, 1   call fmt::v10::vprint(fmt::v10::basic_string_view&lt;char>, fmt::v10::basic_format_args&lt;fmt::v10::basic_format_context&lt;fmt::v10::appender, char> >)@PLT   add rsp, 24   ret<\/code><\/pre>\n<p>\u0414\u0430, \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 <code>std::printf<\/code> \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>print<\/code>, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/fmtlib\/fmt\" rel=\"noopener noreferrer nofollow\">libfmt<\/a>, c <code>printf<\/code> \u0438 <code>ostream<\/code>:<\/p>\n<pre><code class=\"cpp\">#include &lt;cstdio> #include &lt;iostream>  #include &lt;benchmark\/benchmark.h> #include &lt;fmt\/ostream.h>  void printf(benchmark::State&amp; s) {   while (s.KeepRunning())     std::printf(\"The answer is %d.\\n\", 42); } BENCHMARK(printf);  void ostream(benchmark::State&amp; s) {   std::ios::sync_with_stdio(false);   while (s.KeepRunning())     std::cout &lt;&lt; \"The answer is \" &lt;&lt; 42 &lt;&lt; \".\\n\"; } BENCHMARK(ostream);  void print(benchmark::State&amp; s) {   while (s.KeepRunning())     fmt::print(\"The answer is {}.\\n\", 42); } BENCHMARK(print);  void print_cout(benchmark::State&amp; s) {   std::ios::sync_with_stdio(false);   while (s.KeepRunning())     fmt::print(std::cout, \"The answer is {}.\\n\", 42); } BENCHMARK(print_cout);  void print_cout_sync(benchmark::State&amp; s) {   std::ios::sync_with_stdio(true);   while (s.KeepRunning())     fmt::print(std::cout, \"The answer is {}.\\n\", 42); } BENCHMARK(print_cout_sync);  BENCHMARK_MAIN();<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>apple clang 11.0.0<\/em> c \u0444\u043b\u0430\u0433\u0430\u043c\u0438 <em>-O3 -DNDEBUG<\/em> \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043d\u0430 <em>MacOS 10.15.4 <\/em>\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code>Run on (8 X 2800 MHz CPU s) CPU Caches:   L1 Data 32K (x4)   L1 Instruction 32K (x4)   L2 Unified 262K (x4)   L3 Unified 8388K (x1) Load Average: 1.83, 1.88, 1.82 ----------------------------------------------------------- Benchmark                Time             CPU   Iterations ----------------------------------------------------------- printf                87.0 ns         86.9 ns      7834009 ostream                255 ns          255 ns      2746434 print                 78.4 ns         78.3 ns      9095989 print_cout            89.4 ns         89.4 ns      7702973 print_cout_sync       91.5 ns         91.4 ns      7903889<\/code><\/pre>\n<p><code>print<\/code> \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0434\u0435\u0440\u043e\u043c: \u043c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0438\u043c, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0442\u0430\u043a \u043e\u043d \u0435\u0449\u0435 \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u0432 <em>stdout <\/em>\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 14% \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c <em>printf (<\/em>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 \u0432 <em>stdout).<\/em><\/p>\n<p>\u041a\u0430\u043a \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0432 C++? <strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <\/strong><code>std::print<\/code><strong>!<\/strong><\/p>\n<details class=\"spoiler\">\n<summary>\u041d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0434\u0430, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0442 <em>Windows<\/em> \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0432\u0430\u043c \u0441\u043f\u0435\u0440\u0432\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <code>std::print<\/code> \u0432 <em>libc++ <\/em>\u0438 <em>libstdc++. <\/em>\u041f\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043d\u0430 <em>17.07.2023<\/em>, \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0438 \u0442\u0430\u043c, \u043d\u0438 \u0442\u0430\u043c.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u0430\u043c \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0436\u0434\u0430\u0442\u044c, \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/fmtlib\/fmt\" rel=\"noopener noreferrer nofollow\">fmtlib<\/a>.<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/748336\/\"> https:\/\/habr.com\/ru\/articles\/748336\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-350355","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350355"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350355\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}