{"id":6788,"date":"2014-03-15T05:04:50","date_gmt":"2014-03-14T18:04:50","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=6788"},"modified":"2014-03-15T05:04:50","modified_gmt":"2014-03-14T18:04:50","slug":"c-string-function-timings-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-string-function-timings-primer-tutorial\/","title":{"rendered":"C String Function Timings Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings_c.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C String Function Timings Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings_c.jpg\" title=\"C String Function Timings Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C String Function Timings Primer Tutorial<\/p><\/div>\n<p>You don&#8217;t have to use an IDE to do C programming.  There is <a target=_blank title='Digital Mars' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars'>Digital Mars<\/a> C as an example of that.   We have talked about the <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5519'>Xcode command line tools<\/a> before, that frees the gcc compiler to (also) be a command line tool to write C programs from the command line separate to any IDE usage.<\/p>\n<p>So it is today with this tutorial, where we work with Digital Mars C, to time some inhouse and C string library (string.h) library string manipulation functionality.   If you get to compile (recommend <a target=_blank title='Digital Mars download page' href='http:\/\/www.digitalmars.com\/'>Digital Mars C<\/a>) and run this tutorial&#8217;s download at a Windows Command Line (prompt) you will see how fast C is, working way down there near the <a target=_blank title='kernel information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Kernel_%28computing%29'>kernel<\/a> level.   So the second accuracy of <i>time(NULL)<\/i> won&#8217;t pass muster for the timings, and instead, here, we use the <i>clock()<\/i> functionality to get the refinement required to have it mean anything.   Could be affected by so many other things anyway, like what else is running, but is instructive as to what you might have thought was the fastest method.   Personally, love using strstr() to find strings within strings, but, as you can see from the numbers, there are better choices such as strchr() and strpbrk() &#8230; personally, I&#8217;m affronted, gobsmacked, insulted, resigned &#8230; impersonally, I&#8217;m anti-affronted, anti-gobsmacked, anti-insulted, anti-resigned &#8230; the nearby ants,  antily-anti-affronted, antily-anti-gobsmacked, antily-anti-insulted, antily-anti-resigned.<\/p>\n<p>So feel free to download the C programming source code here and rename it to <a target=_blank title='timings.c' href='http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings.c_GETME'>timings.c<\/a><\/p>\n<p>Hope you enjoy this <a target=_blank title=\"Digital Mars compiling\" href=\"http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings_c.jpg\">tutorial<\/a> showing you some command line C dmc (Digital Mars) compilation work.<\/p>\n<p>A really helpful tutorial for code above to do with using clock() is shown <a target=_blank title='Good tutorial 1' href='http:\/\/www.tutorialspoint.com\/c_standard_library\/c_function_clock.htm'>here<\/a> &#8230; thanks.<\/p>\n<p>A really helpful tutorial for C string functionality via string.h is shown <a target=_blank title='Good tutorial 2' href='http:\/\/www.cplusplus.com\/reference\/cstring\/'>here<\/a> &#8230; thanks.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d6788' onclick='var dv=document.getElementById(\"d6788\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d6788' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You don&#8217;t have to use an IDE to do C programming. There is Digital Mars C as an example of that. We have talked about the Xcode command line tools before, that frees the gcc compiler to (also) be a &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-string-function-timings-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[176,234,331,671,997,1205,1283,1319,1435],"class_list":["post-6788","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-c","tag-command-line","tag-digital-mars","tag-kernel","tag-programming","tag-string-functionality","tag-timing","tag-tutorial","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/6788"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=6788"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/6788\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=6788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=6788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=6788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}