<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-7764126179108633515.post4573019703104503769..comments</id><updated>2008-07-21T03:03:39.468+04:00</updated><title type='text'>Comments on Ilya Martynov's blog: STL strings vs C strings for parsing</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.martynov.org/feeds/4573019703104503769/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html'/><author><name>Ilya Martynov</name><uri>http://www.blogger.com/profile/03019237563335985484</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7764126179108633515.post-7928415766686972315</id><published>2008-07-21T03:03:00.001+04:00</published><updated>2008-07-21T03:03:00.001+04:00</updated><title type='text'>cc &amp;&amp;     </title><content type='html'>cc &amp;amp;&amp;amp; &lt;a href="http://rdd.su" title="хеви метал."&gt;    &lt;/a&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/7928415766686972315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/7928415766686972315'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html?showComment=1216594980001#c7928415766686972315' title=''/><author><name>jilcov</name><uri>http://www.blogger.com/profile/13527480015850637359</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html' ref='tag:blogger.com,1999:blog-7764126179108633515.post-4573019703104503769' source='http://www.blogger.com/feeds/7764126179108633515/posts/default/4573019703104503769' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-7764126179108633515.post-8195283294579804117</id><published>2007-12-07T18:26:00.000+03:00</published><updated>2007-12-07T18:26:00.000+03:00</updated><title type='text'>You can do it with std::string, you just have to w...</title><content type='html'>&lt;I&gt;You can do it with std::string, you just have to work with iterator ranges instead of copied substrings.&lt;/I&gt;&lt;BR/&gt;&lt;BR/&gt;I tried do that but while doable it generally makes code more complex as you have to keep two variables to represent the range instead of one for C string. Or am I missing some standard way to represent the range as a single variable? I guess if there was a class with interface similar to string's interface which allows to work on part of other string that would simplify code a lot.&lt;BR/&gt;&lt;BR/&gt;As for safety: my impression that once your are using iterators it is not that much more safer then raw pointers. Standard library doesn't protect you if you ++iterator beyond end() - it is up to programmer to write the code correctly.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/8195283294579804117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/8195283294579804117'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html?showComment=1197041160000#c8195283294579804117' title=''/><author><name>Ilya Martynov</name><uri>http://www.blogger.com/profile/03019237563335985484</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04592666577990406794'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html' ref='tag:blogger.com,1999:blog-7764126179108633515.post-4573019703104503769' source='http://www.blogger.com/feeds/7764126179108633515/posts/default/4573019703104503769' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-7764126179108633515.post-2568136752833666182</id><published>2007-12-07T17:55:00.000+03:00</published><updated>2007-12-07T17:55:00.000+03:00</updated><title type='text'>You can do it with std::string, you just have to w...</title><content type='html'>You can do it with std::string, you just have to work with iterator ranges instead of copied substrings.&lt;BR/&gt;&lt;BR/&gt;If you use typical C idioms (e.g. strchr and pointer arithmetic) then the plain C version probably will be faster.  However, C++ has its own idioms that might perform better (where that might mean faster, or safer, or both)</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/2568136752833666182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/2568136752833666182'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html?showComment=1197039300000#c2568136752833666182' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html' ref='tag:blogger.com,1999:blog-7764126179108633515.post-4573019703104503769' source='http://www.blogger.com/feeds/7764126179108633515/posts/default/4573019703104503769' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-7764126179108633515.post-346524793631294456</id><published>2007-12-06T18:56:00.000+03:00</published><updated>2007-12-06T18:56:00.000+03:00</updated><title type='text'>You should try it with str1 pointing to user-suppl...</title><content type='html'>&lt;I&gt;You should try it with str1 pointing to user-supplied data (e.g. read from stdin or passed in via argv) for a more realistic benchmark.&lt;/I&gt;&lt;BR/&gt;&lt;BR/&gt;Thanks for hint. I just did that (passed the string via arvs) and it does change the result. Though C strings are still faster (~10%) but not as much:&lt;BR/&gt;&lt;BR/&gt;ilya@denmark:~$ g++ -O3 ./test.cc &amp;&amp; ./a.out '              a         '&lt;BR/&gt;Total time:         9.14 sec&lt;BR/&gt;Iterations:         500000000 it&lt;BR/&gt;Time per iteration: 1.828e-05 msec&lt;BR/&gt;Rate:               5.47046e+07 it/sec&lt;BR/&gt;Total time:         10.57 sec&lt;BR/&gt;Iterations:         500000000 it&lt;BR/&gt;Time per iteration: 2.114e-05 msec&lt;BR/&gt;Rate:               4.73037e+07 it/sec&lt;BR/&gt;&lt;BR/&gt;Meanwhile I rewrote my URL parser using C strings and it is now 2x times faster. I guess the speedup comes from the fact that with C strings I can minimize number memory allocations for temporary strings. With C string if you want to take substring of another string you can just take pointer in the middle of the original and place '\0' where substring should end if don't mind destroying the original string. With STL (ok, standart) strings you cannot do this and have to make copies.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/346524793631294456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/346524793631294456'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html?showComment=1196956560000#c346524793631294456' title=''/><author><name>Ilya Martynov</name><uri>http://www.blogger.com/profile/03019237563335985484</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04592666577990406794'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html' ref='tag:blogger.com,1999:blog-7764126179108633515.post-4573019703104503769' source='http://www.blogger.com/feeds/7764126179108633515/posts/default/4573019703104503769' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-7764126179108633515.post-727719924253056843</id><published>2007-12-06T18:17:00.000+03:00</published><updated>2007-12-06T18:17:00.000+03:00</updated><title type='text'>Looks as though GCC is replacing the call to strch...</title><content type='html'>Looks as though GCC is replacing the call to strchr with a compiler builtin, and noticing that str1 points to a literal and doing the search at compile-time.&lt;BR/&gt;&lt;BR/&gt;Unless all the URLs you're parsing are known at compile-time you should try it with str1 pointing to user-supplied data (e.g. read from stdin or passed in via argv) for a more realistic benchmark.&lt;BR/&gt;&lt;BR/&gt;You might be surprised at the result.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/727719924253056843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/727719924253056843'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html?showComment=1196954220000#c727719924253056843' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html' ref='tag:blogger.com,1999:blog-7764126179108633515.post-4573019703104503769' source='http://www.blogger.com/feeds/7764126179108633515/posts/default/4573019703104503769' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-7764126179108633515.post-3499672117686273898</id><published>2007-12-06T18:05:00.000+03:00</published><updated>2007-12-06T18:05:00.000+03:00</updated><title type='text'>I do wish people would stop saying STL when they m...</title><content type='html'>I do wish people would stop saying STL when they mean Standard Library.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/3499672117686273898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7764126179108633515/4573019703104503769/comments/default/3499672117686273898'/><link rel='alternate' type='text/html' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html?showComment=1196953500000#c3499672117686273898' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.martynov.org/2007/12/stl-strings-vs-c-strings-for-parsing.html' ref='tag:blogger.com,1999:blog-7764126179108633515.post-4573019703104503769' source='http://www.blogger.com/feeds/7764126179108633515/posts/default/4573019703104503769' type='text/html'/></entry></feed>