{"id":2990,"date":"2012-08-30T02:42:02","date_gmt":"2012-08-30T02:42:02","guid":{"rendered":"http:\/\/ddolgi.pe.kr\/blog\/index.php\/2012\/08\/30\/cstringcompare-vs-strcmp\/"},"modified":"2012-08-30T02:42:02","modified_gmt":"2012-08-30T02:42:02","slug":"cstringcompare-vs-strcmp","status":"publish","type":"post","link":"http:\/\/ddolgi.pe.kr\/blog\/archives\/2990","title":{"rendered":"[C++]string.compare() vs strcmp()"},"content":{"rendered":"<p><H2><SPAN style=\"FONT-SIZE: 18pt\">\uacb0\uacfc<\/SPAN><\/H2><br \/>\n<P>strA==strA<\/P><br \/>\n<BLOCKQUOTE>==&gt; elapsed time : 1.08 sec<\/BLOCKQUOTE><br \/>\n<P>strA==strB<\/P><br \/>\n<BLOCKQUOTE>==&gt; elapsed time : 1.09 sec<\/BLOCKQUOTE><br \/>\n<P>strcmp(szA,szB)<\/P><br \/>\n<BLOCKQUOTE>==&gt; elapsed time : 0.12 sec<\/BLOCKQUOTE><br \/>\n<P>strcmp(szA,szA)<\/P><br \/>\n<BLOCKQUOTE>==&gt; elapsed time : 0.11 sec<\/BLOCKQUOTE><br \/>\n<P>strcmp(strA,strB)<\/P><br \/>\n<BLOCKQUOTE>==&gt; elapsed time : 0.25 sec<\/BLOCKQUOTE><br \/>\n<P>strcmp(strA,strA)<\/P><br \/>\n<BLOCKQUOTE>==&gt; elapsed time : 0.25 sec<\/BLOCKQUOTE><\/SPAN><br \/>\n<H2>Source Code<\/H2><br \/>\n<PRE class=wiki><br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<\/p>\n<p>#include &lt;string&gt;<br \/>\n#include &#8220;Blib.h&#8221;<\/p>\n<p>using namespace std;<br \/>\n#define TEST_SIZE 1&lt;&lt;20<br \/>\n#define ITER 1&lt;&lt;25<\/p>\n<p>void compare()<br \/>\n{<br \/>\n  string strBuffer1(TEST_SIZE, &#8216;a&#8217;);<br \/>\n  string strBuffer2(TEST_SIZE, &#8216;b&#8217;);<\/p>\n<p>  char szBuffer1[TEST_SIZE+1];<br \/>\n  memset(szBuffer1 , &#8216;a&#8217;, TEST_SIZE);<br \/>\n  szBuffer1[TEST_SIZE]=&#8217;\\0&#8242;;<br \/>\n  char szBuffer2[TEST_SIZE+1];<br \/>\n  memset(szBuffer2 , &#8216;b&#8217;, TEST_SIZE);<br \/>\n  szBuffer2[TEST_SIZE]=&#8217;\\0&#8242;;<\/p>\n<p>  Blib::TStopWatch w;<br \/>\n  puts(&#8220;strA==strA\\n&#8221;);<br \/>\n  for (int i=0;i&lt;ITER;i++)<br \/>\n    strBuffer1 == strBuffer2;<br \/>\n  w.Print(stderr);<\/p>\n<p>  w.Reset();<br \/>\n  puts(&#8220;strA==strB\\n&#8221;);<br \/>\n  for (int i=0;i&lt;ITER;i++)<br \/>\n    strBuffer1 == strBuffer2;<br \/>\n  w.Print(stderr);<\/p>\n<p>  w.Reset();<br \/>\n  puts(&#8220;strcmp(szA,szB)\\n&#8221;);<br \/>\n  for (int i=0;i&lt;ITER;i++)<br \/>\n    strcmp(szBuffer1, szBuffer2);<br \/>\n  w.Print(stderr);<\/p>\n<p>  w.Reset();<br \/>\n  puts(&#8220;strcmp(szA,szA)\\n&#8221;);<br \/>\n  for (int i=0;i&lt;ITER;i++)<br \/>\n    strcmp(szBuffer1, szBuffer1);<br \/>\n  w.Print(stderr);<\/p>\n<p>  w.Reset();<br \/>\n  puts(&#8220;strcmp(strA,strB)\\n&#8221;);<br \/>\n  for (int i=0;i&lt;ITER;i++)<br \/>\n    strcmp(strBuffer1.c_str(), strBuffer2.c_str());<br \/>\n  w.Print(stderr);<\/p>\n<p>  w.Reset();<br \/>\n  puts(&#8220;strcmp(strA,strA)\\n&#8221;);<br \/>\n  for (int i=0;i&lt;ITER;i++)<br \/>\n    strcmp(strBuffer1.c_str(), strBuffer1.c_str());<br \/>\n  w.Print(stderr);<br \/>\n}<\/p>\n<p>main()<br \/>\n{<br \/>\n  compare();<br \/>\n}<br \/>\n<\/PRE><br \/>\n<H2><SPAN style=\"FONT-SIZE: 18pt\">\ubd84\uc11d<\/SPAN><\/H2><br \/>\n\uc5b4\uc774\uc5c6\ub2e4;;; string \uc548\uc5d0 \ubb50\uac00 \ub4e4\uc5b4\uc788\uae38\ub798 \uc800\ub9ac \ucc28\uc774\uac00 \ub098\ub204???<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uacb0\uacfc strA==strA ==&gt; elapsed time : 1.08 sec strA==strB ==&gt; elapsed time : 1.09 sec strcmp(szA,szB) ==&gt; elapsed time : 0.12 sec strcmp(szA,szA) ==&gt; elapsed time : 0.11 sec strcmp(strA,strB) ==&gt; elapsed time : 0.25 sec strcmp(strA,strA) ==&gt; elapsed time : 0.25 sec Source Code #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;string&gt; #include &#8220;Blib.h&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[275],"tags":[278],"class_list":["post-2990","post","type-post","status-publish","format-standard","hentry","category-275","tag-c"],"_links":{"self":[{"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/posts\/2990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/comments?post=2990"}],"version-history":[{"count":0,"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/posts\/2990\/revisions"}],"wp:attachment":[{"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/media?parent=2990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/categories?post=2990"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ddolgi.pe.kr\/blog\/wp-json\/wp\/v2\/tags?post=2990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}