<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kjellkod&#039;s Blog</title>
	<atom:link href="http://kjellkod.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kjellkod.wordpress.com</link>
	<description>KjellKod.cc : Always strive for excellence</description>
	<lastBuildDate>Sat, 25 Feb 2012 17:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kjellkod.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Kjellkod&#039;s Blog</title>
		<link>http://kjellkod.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kjellkod.wordpress.com/osd.xml" title="Kjellkod&#039;s Blog" />
	<atom:link rel='hub' href='http://kjellkod.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Why you should never, ever, EVER  use linked-list  in your code again</title>
		<link>http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/</link>
		<comments>http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 16:00:22 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=490</guid>
		<description><![CDATA[What data structure should you use? What data structure should you avoid? Imagine that you have to use a data structure. It is nothing fancy, only a storage for items that you will use now and then and some later &#8230; <a href="http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=490&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><strong>What data structure should you use?<br />
What data structure should you avoid?</strong></p>
<p><em>Imagine that you have to use a data structure. It is nothing fancy, only a storage for items that you will use now and then and some later on. These items will be inserted, then removed intermittently. They will have some internal order, or significance, to them and be arranged accordingly. Sometimes insertions and removal will be at the beginning or the end but most of the times you will have to find the location and then do an insertion or removal somewhere in between. </em> <em>An absolute requirement is that the insertion and removal of an element is efficient, hopefully even O(1). </em></p>
<p style="padding-left:30px;text-align:center;"><em> <strong>Now, </strong> <strong>what data structure should you use?</strong></em></p>
<p>At a time like this it is good advice to double check with books and/or online resources to verify that your initial hunch was correct. In this situation maybe you recollect that vectors are generally fast for accessing an item but can be slow in modifying operators since items not at the end that are inserted/removed will cause part of the array to be shifted. Of course you also know that an insertion when the vector is full will trigger a re-size. A new array storage will be created and all the items in the vector will be copied and moved to the new storage. This <em>seems</em> <em>intuitively</em> <em>slow</em>.</p>
<p>A linked list on the other hand might have slow O(n) access to the item but the insertion/removal is basically just switching of pointers so this O(1) operations are very <em>much appealing.</em> I double check with a few different online resources and make my decision. Linked-list it is&#8230;</p>
<p style="text-align:center;"><strong><span style="color:#ff0000;">BEEEEEEEEP. ERROR. A RED GNOME JUMPS DOWN IN FRONT OF ME AND FLAGS ME DOWN. HE TELLS ME IN NO UNCERTAIN WAYS THAT I AM WRONG. DEAD WRONG.</span></strong></p>
<p style="text-align:center;"><strong></strong><strong>Wrong? How can this be wrong?</strong><br />
This is what the online resources say:</p>
<p style="padding-left:30px;"><span style="color:#333399;"><em><a href="http://www.cplusplus.com/reference/stl/list/"><span style="color:#333399;">www.cplusplus.com/reference/stl/list</span></a> Regarding std::list</em></span> <span style="color:#333399;"><em>[...] Compared to other base standard sequence containers (<a href="http://www.cplusplus.com/vector"><span style="color:#333399;">vector</span></a>s and <a href="http://www.cplusplus.com/deque"><span style="color:#333399;">deque</span></a>s), lists perform generally better in inserting, extracting and moving elements in any position within the container, and therefore also in algorithms that make intensive use of these, like sorting algorithms.</em></span></p>
<p style="padding-left:30px;"><span style="color:#333399;"><em><a href="http://www.cplusplus.com/reference/stl/vector/"><span style="color:#333399;">www.cplusplus.com/reference/stl/vector</span></a> Regarding std::vector</em></span> <span style="color:#333399;"><em>[...] vectors are generally the most efficient in time for accessing elements and to add or remove elements from the end of the sequence. [...] For operations that involve inserting or removing elements at positions other than the end, they perform worse than <a href="http://www.cplusplus.com/deque"><span style="color:#333399;">deque</span></a>s and <a href="http://www.cplusplus.com/list"><span style="color:#333399;">list</span></a>s.</em></span></p>
<p style="padding-left:30px;"><span style="color:#333399;"><em><a href="http://en.wikipedia.org/wiki/Sequence_container_(C%2B%2B)#List"><span style="color:#333399;">http://en.wikipedia.org/wiki/Sequence_container_(C%2B%2B)#List </span></a>Vectors are inefficient at removing or inserting elements other than at the end. Such operations have O(n) (see <a title="Big-O notation" href="http://en.wikipedia.org/wiki/Big-O_notation"><span style="color:#333399;">Big-O notation</span></a>) complexity compared with O(1) for linked-lists. This is offset by the speed of access — access to a random element in a vector is of complexity O(1) compared with O(n) for general linked-lists and O(log n) for link-trees.</em></span></p>
<p>In this example most insertions/removals will definitely not be at the end, this is already established. So that <strong>should mean</strong> that the linked-list would be more effective than the vector, right? I decide to double check with <a href="http://en.wikipedia.org/wiki/Sequence_container_%28C%2B%2B%29#List" target="_blank">Wikipedia</a>, <a href="http://wiki.answers.com/Q/Difference_between_list_and_vector" target="_blank">Wiki.Answers</a> and <a href="http://en.wikibooks.org/wiki/Data_Structures/All_Chapters#Advantages_.2F_Disadvantages" target="_blank">Wikibooks on Algorithms</a>. They all seem to agree and I cannot understand what the <span style="line-height:24px;"><span style="color:#ff0000;">RED GNOME</span> is complaining about. </span></p>
<p style="line-height:24px;">I take a break to watch <a href="http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style">Bjarne Stroustrup&#8217;s Going Native 2012 keynote</a>. At time 01:44 in the video-cast and slide 43, something interesting happens. I recognize what the <span style="color:#ff0000;">Red Gnome</span> has tried to to tell me. It all falls into place. Of course. I should have known. Duh.<strong> Locality of Reference.</strong></p>
<h2 style="text-align:center;">[ Import Stuff comes now]</h2>
<ol>
<li>It does not matter that the linked-list is faster than vector for inserting/removing an element. In the slightly larger scope that is <strong>completely irrelevant</strong>. Before the element can be inserted/removed <strong>the right location must be found</strong>. And finding that location is extremely slow compared to a vector. In fact, if both linear search is done for vector and for linked-list, then the linear search for vector completely, utterly and with no-contest beats the list.</li>
<li>The extra shuffling, copying overhead on the vector is time-wise cheap. It is dirt cheap and can be completely ignored if compared to the huge overhead for traversing a linked-list.</li>
</ol>
<p><strong>Why</strong>,you may ask? Why is the linear search so extremely efficient for vector compared to the supposedly oh-so-slow linked-list linear search? Is not <strong>O(n)</strong> for linked-list comparable to O(n) for vector?</p>
<p>In a perfect world perhaps, but in reality<strong> it is NOT! </strong>It is here that <a href="http://wiki.answers.com/Q/Difference_between_list_and_vector" target="_blank">Wiki.Answers</a> and the other online resources are wrong! as the advice from them seem to suggest to use the linked-list whenever non-end insertion/removals are common. This is <strong>bad advice</strong> as they completely seem to disregard the impact of &#8220;<em><a href="http://en.wikipedia.org/wiki/Locality_of_reference" target="_blank">locality of reference</a>&#8220;.</em></p>
<p>The linked-list have items in <strong>disjoint areas of memory</strong>. To traverse the list the cache lines cannot be utilized effectively. One could say that the<strong> linked-list is cache line hostile</strong>, or that the linked-list maximizes cache line misses. The disjoint memory will make traversing of the linked-list slow because RAM fetching will be used extensively.</p>
<p>A vector on the other hand is all about having data in adjacent memory. An insertion or removal of an item might mean that data must be shuffled, but this is cheap for the vector. <strong>Dirt cheap </strong><span style="color:#808080;"><em>(yes I like that term)</em></span>. The <strong>vector</strong>, with its adjacent memory layout<strong> maximizes cache utilization</strong> and minimizes cache line misses. This makes the whole difference, and that difference is huge as I will show you.</p>
<p>Let us test this by doing insertions of random integer values. We will keep the data structure sorted and to get to the right position we will use linear search for both vector and the linked-list. Of course this is <em>silly </em>to do for the vector but I want to show how effective the adjacent memory vector is compared to the disjoint memory linked-list.</p>
<div></div>
<h2 style="text-align:center;">[ The Code ]</h2>
<p><pre class="brush: cpp;">
/* &quot;NumbersInVector &amp;randoms&quot; is pre created random values that we just put into a vector. This way the same random values can be used for testing and comparing the vector to the linked-list.

Example:
0, 1, 8, 4, 1     will get sorted to:
0, 1, 1, 4, 8
*/
template &lt;typename Container&gt;
void linearInsertion(const NumbersInVector &amp;randoms, Container &amp;container)
{
 std::for_each(randoms.begin(), randoms.end(),
 [&amp;](const Number &amp;n)
 {
    auto itr = container.begin();
    for (; itr!= container.end(); ++itr)
    {
       if ((*itr) &gt;= n) { break; }
    }
    container.insert(itr, n); // sorted insert
 });
}

/* Measure time in milliseconds for linear insert in a std container */
template &lt;typename Container&gt; 
TimeValue linearInsertPerformance(const NumbersInVector &amp;randoms, Container &amp;container)
{
 g2::StopWatch watch;
 linearInsertion(std::cref(randoms), container);
 auto time = watch.elapsedMs().count();
 return time;
}
</pre></p>
<p>The time tracking (<em><a href="http://kjellkod.wordpress.com/2012/02/06/exploring-c11-part-1-time/" target="_blank">StopWatch</a> that I wrote about it <a href="http://kjellkod.wordpress.com/2012/02/06/exploring-c11-part-1-time/" target="_blank">here</a></em>) is easy with C++11.. Now all that is needed is the creation of the random values and keeping track of the measured time for a few sets of random numbers. We measure this from short sets of 10 numbers all the way up to 500,000. This will give a nice perspective</p>
<p><pre class="brush: cpp;">
void listVsVectorLinearPerformance(size_t nbr_of_randoms)
{
  std::uniform_int_distribution distribution(0, nbr_of_randoms);
  std::mt19937 engine((unsigned int)time(0)); // Mersenne twister MT19937

  auto generator = std::bind(distribution, engine);
  NumbersInVector     values(nbr_of_randoms);

  // Generate n random values and store them
  std::for_each(values.begin(), values.end(), [&amp;](Number &amp;n)
                { n = generator();});

  NumbersInList      list;
  TimeValue list_time = linearInsertPerformance(values, list);
  NumbersInVector    vector;
  TimeValue vector_time = linearInsertPerformance(values, vector);

  std::cout &lt;&lt; list_time &lt;&lt; &quot;, &quot; &lt;&lt; vector_time &lt;&lt; std::endl;
}
</pre></p>
<p>Calling this for values going all the way up to 500,000 gives us enough values to plot them in a graph and which shows exactly what <a href="http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style" target="_blank">Bjarne Stroustrup told us at the Going Native 2012</a>. For removal of items we get a similar curve but that is not as time intensive. I have <a title="google doc linked-list vs vector timing differences" href="https://docs.google.com/spreadsheet/pub?key=0AkliMT3ZybjAdGJMU1g5Q0QxWEluWGRzRnZKZjNMMGc&amp;output=html" target="_blank">google doc collected some timing results</a> that I made on IdeOne.com, my x64 Windows7 / Ubuntu Linux laptop for you to see.</p>
<div class="mceTemp">
<p class="wp-caption-dt"><a href="http://kjellkod.files.wordpress.com/2012/02/linux_insert1.png"><img class="size-full wp-image-492" title="List vs Vector, insert" src="http://kjellkod.files.wordpress.com/2012/02/linux_insert1.png?w=640" alt=""   /></a></p>
</div>
<p class="mceTemp">So 500,000 sorted insertions in a linked-list took some 1 hour and 47 minutes. The same number of elements for the vector takes 1 minute and 18 seconds. You can test this yourself. The code is available at <a href="http://ideone.com/pi2Od">http://ideone.com/pi2Od.</a></p>
<h2 class="mceTemp" style="text-align:center;">[ Locality of Reference ]</h2>
<p class="mceTemp">The <a href="http://www.pugetsystems.com/labs/articles/Specs-Explained-CPU-137">processor and cache architectur</a>e has a lot of influence on the result obviously. On a Linux OS the cache level information can be retrieved by  <em></em></p>
<p class="mceTemp" style="padding-left:30px;"><span style="color:#0000ff;"><em>grep .  /sys/devices/system/cpu/cpu*/index*/cache</em></span></p>
<p class="mceTemp">On my x64 quad-core laptop that gives each core-pair 2x L1 cache a 32 KBytes, 2x L2 cache a 256 KBytes. All cores share a 3 MBytes L3 cache.</p>
<div id="attachment_543" class="wp-caption alignnone" style="width: 541px"><a href="http://kjellkod.files.wordpress.com/2012/02/inteli5conceptualdrawingquad-core.png"><img class="size-full wp-image-543" title="inteli5conceptualdrawingquad-core" src="http://kjellkod.files.wordpress.com/2012/02/inteli5conceptualdrawingquad-core.png?w=640" alt=""   /></a><p class="wp-caption-text">Conceptual drawing of quad core Intel i5</p></div>
<p class="mceTemp">I thought it would be interesting to compare my quad-core against a simpler and older computer. Using the <a href="http://www.cpuid.com/softwares/cpu-z.html" target="_blank">CPU-Z freeware software</a> I got from my old dual-core Windows7 PC that it has 2xL1 caches a 32KBytes and 1xL2 cache a 2048 KBytes.</p>
<p class="mceTemp">Testing both with a smaller sets of values shows the cache significance clearly<em> (disregarding different bus bandwidth and CPU Speed </em>)</p>
<div id="attachment_544" class="wp-caption alignright" style="width: 610px"><a href="http://kjellkod.files.wordpress.com/2012/02/x86-old-pc-win7-finegrained.png"><img class="size-full wp-image-544" title="x86-old-pc-win7-finegrained.png" src="http://kjellkod.files.wordpress.com/2012/02/x86-old-pc-win7-finegrained.png?w=640" alt=""   /></a><p class="wp-caption-text">x86 old dual-core PC</p></div>
<div id="attachment_545" class="wp-caption alignright" style="width: 610px"><a href="http://kjellkod.files.wordpress.com/2012/02/x64-win7-finegrained.png"><img class="size-full wp-image-545" title="x64-win7-finegrained.png" src="http://kjellkod.files.wordpress.com/2012/02/x64-win7-finegrained.png?w=640" alt=""   /></a><p class="wp-caption-text">x64 quad-core Intel i5</p></div>
<h2 class="mceTemp" style="text-align:center;">[ Devil's Advocate ]</h2>
<p>The example above is of course somewhat extreme. This integer example brings out another bad quality of linked-list. The linked-list need 3 * size of integer to represent one item when the vector only need 1. So for small data types it makes even less sense to use a linked-list. For larger types you would see the same behavior as shown above but obviously the times would differ.</p>
<h2 class="mceTemp" style="text-align:center;">[What to do now?]</h2>
<p class="mceTemp">Donald Knuth made the <a href="http://en.wikipedia.org/wiki/Program_optimization#When_to_optimize">following statement</a> regarding optimization:<em><br />
</em></p>
<p class="mceTemp" style="text-align:center;"><em> &#8220;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil&#8221; </em>.</p>
<p>Meaning that &#8220;<em>Premature Optimization</em>&#8221; is when the software developer thinks he is doing performance improvements to the code without knowing for a fact that it is needed or that it will greatly improve performance. The changes made leads to a design that is not as clean as before, incorrect or hard to read. The code is overly complicated or obfuscated. This is clearly an anti-pattern.</p>
<p>On the other hand we have the inverse of the extreme <em>Premature Optimization</em> anti-pattern, this is called <strong><em>Premature Pessimization</em></strong><em>. Premature pessimization</em> is when the programmer chose techniques that are known to have worse performance than other set of techniques. Usually this is done out of habit or just because.</p>
<p>Example 1: Always copy arguments instead of using const reference.<br />
Example 2: Using the post increment ++ operator instead of pre increment ++. <em>I.e value++ instead of ++value</em>.</p>
<p>For incrementing native types pre- or post-increment is of little difference but for class types the performance difference can have an impact. So using value++ always is a bad habit that when used for another set of types actually is degrading  performance. For this reason it is always better to just do pre increments. <strong>The code is just as clear</strong> as post increments and <strong>performance will always be  better</strong> (<em>albeit usually only a little better</em>).</p>
<p>Using linked-list in a scenario when it has little performance benefit <em>(say 10 elements only touched rarely</em>) is still worse compared to using the vector. It is a <strong>bad habit</strong> that you should just stay away from.</p>
<p>Why use a bad performance container when other options are available? Options that are just as clean and easy to work with and have no impact on code clarity.</p>
<p>Stay away from <em>Premature </em><em>Optimization</em> but be sure to not fall into the trap of <em>Premature Pessimization! </em>You should follow the best (optimal) solution, and, of course, common sense <span style="text-decoration:underline;">without</span> trying to optimize and obfuscate the code and design. Sub-optimal techniques such as linked-list should be avoided since there are clearly better alternatives out there.</p>
<h2 style="text-align:center;">[ C++ only? ]</h2>
<p>Of course this is true for other languages as well. I leave it as a <em>fun</em> test for whomever feel challenged to test for C#.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/490/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=490&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>

		<media:content url="http://kjellkod.files.wordpress.com/2012/02/linux_insert1.png" medium="image">
			<media:title type="html">List vs Vector, insert</media:title>
		</media:content>

		<media:content url="http://kjellkod.files.wordpress.com/2012/02/inteli5conceptualdrawingquad-core.png" medium="image">
			<media:title type="html">inteli5conceptualdrawingquad-core</media:title>
		</media:content>

		<media:content url="http://kjellkod.files.wordpress.com/2012/02/x86-old-pc-win7-finegrained.png" medium="image">
			<media:title type="html">x86-old-pc-win7-finegrained.png</media:title>
		</media:content>

		<media:content url="http://kjellkod.files.wordpress.com/2012/02/x64-win7-finegrained.png" medium="image">
			<media:title type="html">x64-win7-finegrained.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Exploring C++11, part 1 (Time)</title>
		<link>http://kjellkod.wordpress.com/2012/02/06/exploring-c11-part-1-time/</link>
		<comments>http://kjellkod.wordpress.com/2012/02/06/exploring-c11-part-1-time/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 20:07:18 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=458</guid>
		<description><![CDATA[I was playing around with C++11 the other day &#8211; being inspired and all by the 2012 Going Native videocasts. So far I have only seen the keynote by Stroustrup but that was enough to get me inspired Anyhow,.. I &#8230; <a href="http://kjellkod.wordpress.com/2012/02/06/exploring-c11-part-1-time/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=458&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was playing around with C++11 the other day &#8211; being inspired and all by the <a href="http://channel9.msdn.com/Events/GoingNative/GoingNative-2012">2012 Going Native</a> videocasts. So far I have only seen the keynote by Stroustrup but that was enough to get me inspired <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyhow,.. I decided to put down some random pieces of code and thoughts that were running through my head in the past,. maybe a code snippet or two is useful to you as well?</p>
<h2>1. Time</h2>
<p>OK, so with C++11 we get this whole nice feature to deal with time in different ways. Previously this was not cross-platform standardized and even thread unsafe for the ANSI functions. Time and time again (<span style="color:#808080;">pun intended</span>) we allways run into the task of measuring the time between two points,. and sometimes, just sometimes, it is nice to force a &#8220;wait/sleep&#8221; either for fun or for testing. This would be easy to do with C++11 but due to its very verbose syntax it can be confusing to get it right. Perhaps these snippets might help?</p>
<p><span id="more-458"></span></p>
<p>Check out in my artificial examples, like the <span style="color:#0000ff;">silly_sleep_ms(&#8230;)<span style="color:#000000;"> and you will see what I mean</span><br />
</span></p>
<p><pre class="brush: cpp;">
#include &lt;iostream&gt;
#include &lt;chrono&gt;
void silly_sleep_ms(unsigned int ms)
{
  typedef std::chrono::high_resolution_clock clock;
  typedef std::chrono::milliseconds milliseconds;

  clock::time_point t0 = clock::now();
  std::this_thread::sleep_for(milliseconds(ms));
  clock::time_point t1 = clock::now();
  milliseconds total_ms = std::chrono::duration_cast&lt;milliseconds&gt;(t1 - t0);

  std::cout &lt;&lt;&quot;this_thread_sleep (&quot; &lt;&lt; ms &lt;&lt;&quot;) milliseconds: &quot;
            &lt;&lt; total_ms.count() &lt;&lt; &quot;ms\n&quot;;
}
</pre></p>
<p>Running <span style="color:#0000ff;">silly_sleep_ms(50)</span> three times yield:<br />
<span style="color:#993366;">this_thread_sleep 50 milliseconds: 52ms</span><br />
<span style="color:#993366;">this_thread_sleep 50 milliseconds: 51ms</span><br />
<span style="color:#993366;">this_thread_sleep 50 milliseconds: 51ms</span></p>
<p>On my ancient PC (<span style="color:#808080;">Intel Core 2-CPU 6400 @ 2.13GHz</span>) running Windows7 it is usually slightly worse performance than when I boot up for Ubuntu. But on windows7 this seemed to be typical with a couple of milliseconds difference. No big deal, right?.</p>
<p>Of course repeating all the <span style="color:#0000ff;">typedefs</span> and template arguments all the time is kind of tedious. A simple <span style="color:#0000ff;">StopWatch</span> utility makes things easier,. so with an attempt at refactoring it.</p>
<p><pre class="brush: cpp;">
namespace whatever // formatted for blog readability
{
  typedef std::chrono::high_resolution_clock clock;
  typedef std::chrono::microseconds microseconds;
  typedef std::chrono::milliseconds milliseconds;

  clock::time_point now(){return clock::now();}

  microseconds intervalUs(const clock::time_point&amp; t1, const clock::time_point&amp; t0)
 {
    return std::chrono::duration_cast&lt;microseconds&gt;(t1 - t0);
 }

  milliseconds intervalMs(const clock::time_point&amp; t1,const clock::time_point&amp; t0)
 {
    return std::chrono::duration_cast&lt;milliseconds&gt;(t1 - t0);
 }



class StopWatch
{
   clock::time_point start_;
 public:
   StopWatch() : start_(clock::now()){}
   clock::time_point restart() { start_ = clock::now(); return start_;}
   microseconds elapsedUs()    { return intervalUs(now(), start_);}
   milliseconds elapsedMs()    { return intervalMs(now(), start_);}
};

} // whatever

</pre></p>
<p>This cuts down the verbose syntax needed for the <span style="color:#0000ff;">silly_sleep_ms(&#8230;)</span> function</p>
<p><pre class="brush: cpp;">
void silly_sleep_ms(unsigned int ms)
{
 using namespace whatever;
   StopWatch measure;
   std::this_thread::sleep_for(g2::milliseconds(ms));

   std::cout &lt;&lt;&quot; 2this_thread_sleep (&quot; &lt;&lt; ms &lt;&lt;&quot;) milliseconds: &quot;
             &lt;&lt; measure.elapsedMs().count() &lt;&lt; &quot;ms\n&quot;;
}
</pre></p>
<p>Running it instead for microseconds (us) the overhead is proportionally much higher (not as bad if running on Linux).</p>
<p><pre class="brush: cpp;">
void silly_sleep_us(unsigned int us)
{
 using namespace whatever;
    StopWatch measure;
    std::this_thread::sleep_for(microseconds(us));

    std::cout &lt;&lt;&quot; this_thread_sleep (&quot; &lt;&lt; us &lt;&lt;&quot;) microseconds: &quot;
              &lt;&lt; measure.elapsedUs().count() &lt;&lt; &quot;us\n&quot;;
}
</pre></p>
<p>Running <span style="color:#0000ff;">silly_sleep_us(50)</span> three times yield:<br />
<span style="color:#993366;">this_thread_sleep (50) microseconds: 1792us</span><br />
<span style="color:#993366;">this_thread_sleep (50) microseconds: 1151us</span><br />
<span style="color:#993366;">this_thread_sleep (50) microseconds: 1921us</span></p>
<p><strong>Whoa</strong>. The overhead just went from some meager 4% overhead to 38 times the expected time and actually getting closer to 2 milliseconds for some calls. Repeating this even more times just confirms that this result was not unusual but what is to be expected!</p>
<p>Being Windows rusty and all and doing this a late night last year together with packing (<span style="color:#808080;"><em>for paternal leave in the USA</em></span>) made my sleepy brain more befuddled than usual.</p>
<h3 style="text-align:center;"><span style="color:#808080;"><em>Mental note to self:<br />
Do not try to do snippet programming examples and pack at the same time</em></span></h3>
<p>For some reason I actually thought I had seen a bug since I tested the same code on Linux and the overhead was not nearly as high. In a temporary state of confusion I emailed Anthony Williams (creator of just::thread and the <span style="color:#0000ff;">chrono</span> library that I use). He very nicely replied to my email explaining that<br />
<strong></strong>&#8220;<span style="color:#333399;"><em>&#8230; the smallest timer tick granularity on Windows is 1 millisecond, so it is hard to sleep for less than that, and the standard says that sleep_for sleeps for *at least* the specified tim</em></span><span style="color:#808080;"><span style="color:#333399;"><em>e</em></span>.&#8221; </span></p>
<p>Duh! Reading it on the plane made me feel more than a little silly. Of course. Anthony was even so nice as to suggest a snipped for shorter sleep. Using <span style="color:#0000ff;">this_thread::yield</span> in a loop with the <span style="color:#0000ff;">high_resolution_clock</span> would get better result. The tradeoff being that the operation on Windows would in itself be a time consuming operation,. maybe even yielding as bad result as before.</p>
<p><pre class="brush: cpp;">
template&lt;typename Duration&gt;
void short_sleep(Duration d) // thanks to Anthony Williams for the suggestion of short_sleep
{
   clock::time_point const start=clock::now(), stop=start+d;
   do{
       std::this_thread::yield();
     } while(clock::now()&lt;stop);
}

// ... updated for using the new sleep utility
void silly_improved_short_sleep_us(unsigned int us)
{
  using namespace whatever;
  StopWatch measure;
  short_sleep(microseconds(us));
  auto elapsed_us = measure.elapsedUs().count();

  std::cout &lt;&lt;&quot;this_thread_sleep (&quot; &lt;&lt; us &lt;&lt;&quot;) microseconds: &quot;
            &lt;&lt; elapsed_us &lt;&lt; &quot;us\n&quot;;
}
</pre></p>
<p>Running a modified version of the <span style="color:#0000ff;">silly_sleep_us</span>, using the <span style="color:#0000ff;">short_sleep</span> gave for three tries<br />
<span style="color:#800080;">this_thread_sleep (50) microseconds: 51us</span><br />
<span style="color:#800080;">this_thread_sleep (50) microseconds: <strong>295</strong>us</span><br />
<span style="color:#800080;">this_thread_sleep (50) microseconds: 51us</span></p>
<p>Running it even more times show that the result is more inconsistent then what I first expected. Just like Anthony suggested using the <span style="color:#0000ff;">high_resolution_clock</span> is sometimes as fickle as the original <span style="color:#0000ff;">this_thread_sleep</span>.</p>
<p>So way better than before but still shaky. Shaky is still better than always way out there I suppose. But what is <strong>better</strong> is <strong>naturally </strong>the improved syntax with or without the StopWatch. Instead of writing very verbose like as shown before:</p>
<p><pre class="brush: cpp;">
typedef std::chrono::high_resolution_clock clock;
typedef std::chrono::milliseconds milliseconds;

  clock::time_point t0 = clock::now();
  // ... some operation to time estimate
  clock::time_point t1 = clock::now();

  milliseconds total_ms = std::chrono::duration_cast&lt;milliseconds&gt;(t1 - t0);
</pre></p>
<p>All you need to do is to use a StopWatch or similar grouped functionality and you cut it down to</p>
<p><pre class="brush: cpp;">
StopWatch measure;
// ... some operation to time estimate

auto elapsed_us = measure.elapsedUs().count();
</pre></p>
<p>Or just using the namespace <span style="color:#0000ff;">whatever</span> as used above</p>
<p><pre class="brush: cpp;">
clock::time_point t0 = now();
// ... some operation to time estimate
clock::time_point t1 = now();

auto elapsed_ms = intervalMs(t1, t0).count();
</pre></p>
<p>There you go, with C++11 it is a snap to pin down elapsed time no matter if you are on Windows or on Linux. Unfortunately we have this verbose template syntax that will scare away many newcomers and till it gets simpler I suggest you to use something like the <span style="color:#0000ff;">StopWatch</span> or the <span style="color:#0000ff;">whatever</span> functionality above.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/458/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/458/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=458&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2012/02/06/exploring-c11-part-1-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>The hiring process &#8230; 11 years of success and failures</title>
		<link>http://kjellkod.wordpress.com/2012/02/01/the-hiring-process-11-years-of-success-and-failures/</link>
		<comments>http://kjellkod.wordpress.com/2012/02/01/the-hiring-process-11-years-of-success-and-failures/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 06:00:45 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[rambling]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=317</guid>
		<description><![CDATA[This blog entry is long overdue. Now I am benched until the contract with my next client is finalized. So this time is as good as ever to finally pin this down&#8230; The last 11 years took me, then my &#8230; <a href="http://kjellkod.wordpress.com/2012/02/01/the-hiring-process-11-years-of-success-and-failures/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=317&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog entry is long overdue. Now I am <em>benched</em>  until the contract with my next client is finalized. So this time is as good as ever to finally pin this down&#8230;</p>
<p>The last 11 years took me, then my family, over two continents and three countries in search of job and home. It was an interesting journey and will continue to be so I suspect.</p>
<p>After <a href="http://www.linkedin.com/in/kjellkod">11 years and a few different jobs</a> I have made some conclusions, mental notes that I figured was worth mentioning, at least to my self. Maybe in writing it down I will get some clarity in all of this. A lot of times that is how I work. In telling someone else, or just writing it down the pieces just fall into place.</p>
<p>And yes this blog is kind of longish. It is an entry actually written for myself. You are not intruding if you are reading it &#8211; but it is long and rambling so beware if you continue to read it. You might get bored. Also this story is completely egocentric &#8211; after all it is my story.</p>
<p>In fact I suggest you do something else with your time. If you really want to read interesting blogs then I suggest you check out <a href="http://sites.google.com/site/steveyegge2/you-should-write-blogs">Steve Yegge</a> a blog virtuoso who is stealing way too much of my spare time since I <em>discovered </em>him last week</p>
<p>If I have any points to make apart from memory reminiscing they will probably be scattered in hard to find places, or not at all, so this is a good time to stop reading before you have lost too much of your own personal time.</p>
<p style="padding-left:30px;">
<p><span id="more-317"></span></p>
<p><strong>Still reading?</strong> Do not say I did not warn you.</p>
<p>I graduated from the <a href="http://www.ltu.se/?l=en">Lulea University of Technology</a> in early 2001. I was all green, eager to understand what working was all about. I mean <strong>working</strong> with <strong><a href="http://en.wikipedia.org/wiki/Computer_science">CS</a></strong>. All my previous work experience had mostly entailed manual labor. Some of my previous working experience was just silly hard,. and even mentioning it now will make you sneer and think I am being ludicrous.</p>
<p>Even so. I really got my first work experience during some winter weekends with my dad and brother Hedas. Our house in <a href="http://maps.google.com/maps?q=google+maps+alvik+sweden+lule%C3%A5&amp;hl=en&amp;ie=UTF8&amp;ll=53.225768,-6.679687&amp;spn=98.990753,165.234375&amp;client=firefox-a&amp;hnear=Alvik,+Norrbotten+County,+Sweden&amp;t=m&amp;z=3&amp;iwloc=A">Alvik </a>was heated with a huge (well I thought so then) incinerator. As the temperature crept down to -30C  (-22 Fahrenheit), even touching &#8211; 40C sometimes, we needed a lot of firewood. My dad did this <em>lumberjack-hobbyist-for-fun-and-for-necessity</em> every winter weekend until we had enough firewood for the next season. It was manual work, chainsaw (for my dad, not for me), saw and axe. The cut down trees were stripped of branches until they were just timber. Then my brother and I took these logs and piled them. It was a lot of dragging, pulling, lifting. I always tried to take as big logs as my 2 year older brother. I probably did not succeed very often, but I tried. I was 7 when I started helping out in the forest.</p>
<p>I am not saying that my life was hard. I was happy, this was fun. I am just trying to build up some character here so you (I) understand why things happened later as it happened. Why I am the way I am.</p>
<p>At 13 I got my<a href="http://www.hugosons.se/Default.aspx?p=740"> first summer job</a>. I was slaving away, well at least working long days, with painting buildings, laying cement building foundations, cleaning pig stables, bringing in the hay and other pretty hard tasks for a 13 year old. I continued to work some summers at the pig farm. It totally sucked and the pay was low, the people there mostly made fun of the scrawny young kids that awkwardly tried to do  grown-up jobs but finding a summer job was not so easy so this is what was available.</p>
<p>At 27 my past work experiences encompassed not only farm work but also working with <em>no-safety</em> sawmills ( I am <strong>so</strong> glad I did not loose any fingers),  summer nights at a bakery doing the last touch on Danish pastry and surveing huge ovens and their outgoing bread lines., I did monotonic work in the assembly lines and technical fix-it support for a <a href="http://liko.se">local healthcare company</a>. At later years when I was at the university I also got some work at a day-care center and of course being the<a href="http://www.hemglass.se/Om-Hemglass.aspx"> ice-cream truck man</a> for Hemglass rocked (<em>Hemglass</em> <em>is the Swedish version of the &#8220;Schwans truck&#8221;</em>).</p>
<p>So back in 2001 I knew what manual labor type of work was all about. Unfortunately I knew absolutely zero about real software engineering. Just a year previous I really sucked, yes really <strong>sucked</strong> at programming. My lab partner Pär Hellström was then my constant programmer buddy. We collaborated about what do do, but when it came down to coding the <span style="color:#888888;">loops</span>, the <span style="color:#888888;"><em>;</em></span> and the <span style="color:#888888;"><em>if&#8217;s then else</em></span> he was just so much faster than I was. Whenever I tried it was just too many forgotten<span style="color:#999999;"> ;</span> or <em>slow-to-look-up</em> library calls that made it too <em>staccato</em> for our mutual enjoyment. Out of convenience for both of us Pär took charge of all the coding. It gave me good practice at reading code, following and pointing out improvements and thinking ahead for the <em>what-to-do-next</em> instructions but actually coding, really <em>coding,</em> was slow going for me.</p>
<p>Then during my <em>way-too-long</em> Master Thesis work for professor<a href="http://www.seas.upenn.edu/~guerin/"> Roch Guerin</a> at his lab at UPenn something happened. Maybe it was cracking away at <a href="http://en.wikipedia.org/wiki/Open_Shortest_Path_First">OSPF</a> server code, maybe it was failing miserably at becoming good at C++ templates or maybe it was seeing glimpses of what really good C++ object oriented server code could be in contrast to messy <span style="color:#888888;">#ifdef</span> cluttered C-code. Either way I got boosted. I realized I really liked programming. C++ was fun. Code and how it all made sense in a higher design and that source code could be beautiful in a way that I never even came close to glimpse during my university studies.</p>
<p>So when I handed in my Master&#8217;s Thesis (probably only a <a href="http://epubl.ltu.se/1402-1617/2001/124/LTU-EX-01124-SE.pdf">stumbling approach to be academic</a>) it felt like a fundamental life-step. I was ready, eager and anticipating a <em>change</em>. A life change. Professional life change. I so badly wanted to work with my new found skills. To prove myself, to learn and do do something useful. Now all I had to do was to find my job.</p>
<p>&#8230; Not as easy as it sounds. For me it took almost 2 years before I reached what I was looking for.</p>
<h2 style="padding-left:30px;"><span style="color:#888888;">2001 &#8211; A kindling fire</span></h2>
<p>The job market in Luleå was just not for a young aspiring C++ programmer. I tried and tried and no one got back to me. All my sent out resumes and cold calls was just rewarded with the wall of silence. Not even a written <em>rejection letter</em> from the companies I contacted. <em>.. Well maybe one or two letters. Hey, this is <strong>my</strong> story I can choose to forget, mix-up, misplace and distort &#8211; if that helps in getting it out, . .</em></p>
<p>&#8230; I reconsidered. Maybe the www tech had something to offer? I had dabbled with php at the University and applied for a web-editing job at the local newspaper, <a href="http://www.kuriren.nu/nyheter/">Kuriren</a>. Out of over 300 applicants, a few got selected for an interview. I was one of the lucky few. All eager, all <em>ready</em> I was quickly shot downed, burned and rejected. All of the applicants had enough php experience &#8211; what the team really wanted was the applicant to be a good golfer and an ardent fly fisher. I was neither.</p>
<p>Someone, I do not remember who, told me to stop sending out my resume and just go to the companies and visit them in person. I looked over my list of companies that I had applied to. All had so far given me the silent treatment. I started to work down the list.</p>
<p>At my second try, at (Swedish: &#8220;<em>Förenkla Din Tillvaro</em>&#8220;) <a href="http://www.fdt.se/">FDT</a> I got to talk to the president. From behind his desk the CEO Kent Forss looked up at me and said</p>
<p><strong>Kent:</strong> &#8220;<em>Oh. So you are Kjell? I just deleted your CV from my inbox&#8221;</em><br />
<span style="color:#888888;">Silence. Awkward silence for an eternity.</span></p>
<p>I <em>jumped-started</em> my brain and manage to squeak out something about that<br />
<strong>Me: &#8220;</strong><em> it is a Good Thing I had another CV with me ..</em>.&#8221;</p>
<p>As Kent and I was talking the lead programmer Peter Joki walked by and got interested. It turned out the he was in dire need of more people and once the president talked to him I had in just 5 minutes landed my first job. <strong>Yeeaaay</strong>!</p>
<p>Months later and happy coding in Visual Basic 6, porting old code from Visual Basic 3, laying down the foundation and coding a <a href="http://www.fdt.se/butiksdata/for-enskild-butik/FDT-Butik-PE/">whole new piece of software</a> and playing with software design I did something unexpected. I quit my job. The job was fun, the company and the colleagues had fun together but in the end it was not for me. I wanted more, or at least I wanted something else.</p>
<p>I wanted to work with C++ and I wanted to learn on a whole different level than I could at FDT. I wanted to work with the best and the brightest. I am not saying that the develpers at FDT were not the best and brightest but it was too close to home, and it was not the cutting-edge, world changing software that I dreamed about. After 8+ months in the USA I wanted more of the world than Luleå. I wanted <a href="http://khayyam.seas.upenn.edu/">UPenn </a>at a company-level. So I pondered and pondered. In Sweden the job market for Software Engineers seemed shot. <a href="http://www.ericsson.com/">Ericsson</a> had already started to lay off engineers and in the two years that followed <a href="http://www.ericssonhistory.com/templates/Ericsson/EricssonBook/Article.aspx?id=3912&amp;epslanguage=EN">the company lay-offs basically killed the job market</a> for newly graduated software wannabees. The repercussions of that we can still feel today. I blame (<em>probably completely biased and wrongfully</em>) Ericsson as the No.1 reason why computer science went from being popular at the universities to something obscure. I decided to leave the country.</p>
<p>In retrospective I think it was good that I tried to get away from Sweden. Judging from the reactions of friends and acquaintances I did something crazy, ballsy and utterly <em>loco</em>. I went to the bank, took out a loan of 100.000 SEK and went abroad. I had no security for the loan, no job but somehow I managed to persuade the banker of my golden opportunities.</p>
<p>After a short vacation in Spain I was back in Philadelphia. I was going to find a job in the USA. A potentially serious relationship waited there and I thought I could pull it off. My skunkwork agenda was to find a company that would sponsor my visa, then go back to Sweden and apply for the sponsored-visa. It was gutsy, not how normal people would have done it and in the end it came down hard on me. I learned a lot in the process and have never, ever, regretted it.</p>
<p>In the end the relationship went sour and I was just feeling miserable in Philadelphia. Sure enough feeling miserable does not improve anyone&#8217;s job hunting chances, but what really killed my chances was Mr terrorist, Bin Laden himself. On September 11th, 2001 I had my second, maybe final job interview for a company in the international bank market. My profile was perfect for them as they for their <em>Operations </em>department wanted someone European who also knew at least one Nordic language. I think I almost had the job. As we were discussing salary the interview got interrupted by the secretary. The towers were hit. You all know what happened after that&#8230; All my chances in the USA were killed that day, my relationship had already gone from sour to rancid and now the whole world, not only the USA was in turmoil.</p>
<p>A few weeks later I was back in Luleå. Most of my borrowed money spent and with a loan that demanded monthly payments I had to get creative quickly. Lots of luck and a mismatch of odd-jobs helped me. For almost a year I got by as a substitute teacher, on-and-off assignments for the vampire run StudentConsulting with everything from teaching Visual Studio IDE and Visual Basic programming to making small ActiveX components and attempts at www intranet hacking (<em>hacking in the meaning of creating, not destroying</em>).</p>
<p>My last odd-job was doing the dishes at a local Chinese/Pizzeria restaurant. Oddly enough I never considered that to be an <em>all-time low</em>. In fact I think I learned a lot from <a href="http://www.restaurangportal.se/restaurang/restaurang+waldorf,r1976.html">Waldorf</a> and I think of that time as something profound where I finally could get some much needed mental meditation as I was cleaning up and washing cups, plates and fragile things that I tried not to break or chip.</p>
<h2 style="padding-left:30px;"><span style="color:#888888;">October 2002. The Dawn of the Software Engineer</span></h2>
<p>Lots and lots and lots of cold calls, company visits, job applications, travel to Stockholm and back to Luleå again, a few job interviews, loosing myself with loser childhood delinquent friends. Loosing the same friends. Loosing other friends. Gaining some friends.<br />
It was a negative spiral only made slightly positive by my refusal to give up. I was desperately trying to learn about myself &#8211; and in the same time I involuntarily learned some about the beauty and cruelty of the world and the people in it. I tried to desperately understand and learn from my mistakes and was hoping and <em>striving</em> for a better tomorrow. A better me. That one year I spent was a year in clarifying and purifying turmoil. It was my personal inferno, my purgatory.</p>
<p>Then out of the blue it came. As I was vacuuming at the restaurant someone called me. Finally. A Company. A reply. <a href="http://www.parkairsystems.com/index.php/Air-Traffic-Management-Surveillance.html">Park Air Systems</a> (PAS) in Horten, Norway. It was my dream. It was C++. It was something that <strong>mattered</strong>. They made a <strong>difference</strong>. I had a stumbling job interview over the phone. Norwegian and Swedish are supposed to be similar. For me it was not. To this day I cannot fathom how I made it past the first stumbling phone interview, but I did.</p>
<p>Some time later I was in Horten for my second and final job interview.The day before I had walked through the town all the way to the company location. I wanted to know exactly where it was. What the company looked like from the outside, how long time would it take me to walk from the hotel to PAS. In the afternoon I tried to grasp what the community of Horten was like and close to the end of the work day I remember that I called the secretary and asked about dress code. Good thing I did.</p>
<p><strong>Me:</strong> &#8220;<em>Should I wear a suit or be more casual dressed&#8221;.</em></p>
<p>The secretary told me with a laugh and with no room for misunderstanding<br />
<strong>Her:</strong> &#8220;<em>Hvis du ønsker jobben må du IKKE ha på deg en dress, du må komme uformell kledd</em>&#8221;   (If you want the job, DO NOT wear a suit, you must come dressed casual)</p>
<p>She was right. Just maybe I also had something to offer in addition to not wearing a suit? Either way I got the job as a Software Systems Engineer for <em>Operations </em>working with Air Traffic Surveillance. It was very exciting. Very important. And I was finally and officially <em>an Engineer</em> albeit a <strong>very junior</strong> one at that.</p>
<p>Park Air Systems (PAS) had basically only senior skilled-level engineers working at <em>Operations</em> and <em>Development</em>. After 4 years there I had worked as a junior developer, done my best as a <em>Software Responsible</em> for <a href="http://en.wikipedia.org/wiki/Comodoro_Arturo_Merino_Ben%C3%ADtez_International_Airport">AMB Chil</a>e and Heathrow <a href="http://www.lucasuk.com/images/projectphotos/ControlTower.jpg">old</a> and <a href="http://en.wikipedia.org/wiki/File:Heathrow_Tower_%2870279616%29.jpg">new tower</a>. I was doing problem solving, system integration, performance and system tuning more than I was doing programming. I wanted to do more with <em>software</em> and I realized or at least <em>felt </em>that I would always be junior at PAS and always only do <em>junior </em>software developing assignments, if any. I was simply too good at being a <em>Software Responsible</em> in comparison to my skills as a relatively bleak (<em>junior</em>) software developer. There was no need or desire for the company to let me explore my software coding skills. In the end we, my wife and I (yes I managed to get married too, but that&#8217;s a whole <a href="http://sites.google.com/site/kjellandjeanine/oursaga">other story</a>) decided it was time to move back to Sweden.</p>
<p>In retrospective the Norwegian era was amazing. I had found a new belief in myself, managed to do some good work, whetted my appetite for coding and I got glimpses of how very good software could look like. My coding style is definitely colored by the experiences I made at PAS, by the C++ gurus I met. They helped to create the image of how I wanted to be as a software engineer.<br />
&#8230;<br />
After four years in Horten I could look back on that day in 2002 when I had gone to Norway with a hope of a software future, a woman that loved me, a job that was promising and a hint of martial art in the background. I am very grateful for my time in Norway and Horten, PAS and friends will always have a special place in my heart.</p>
<h2 style="padding-left:30px;"><span style="color:#888888;">2006, kindred spirits and an appetite to learn</span></h2>
<p>At <a href="http://hiq.se/en/">HiQ-Stockholm</a> I found kindred spirits. They had a passion for software that helped me exhume half-buried coding skills. It fed my desire to <em>excel</em>, to prove to myself that I had it in me. The whole company felt vibrant and positive. You could actually feel it at the company. It was in the atmosphere. It was felt from within, throughout from the core to its client-based consultants. Even today when I no longer work for HiQ I am amazed by what the CEO <a href="http://www.linkedin.com/pub/lars-stugemo/5/627/84">Lars Stugemo</a> has achieved. I am convinced that his positive nature has created the HiQ company soul. The &#8220;<em>If it is to be, it is up to me&#8221;</em> motto we were using back in the days was not only an empty company value and vision but became very personal for me and many other employees.</p>
<p>I still try to live by that motto &#8211; if there is a change that I desire, that change should start with me. Be a doer, be active, to show by example, lots of guts and will was always in me but it really bloomed at HiQ. I owe a huge debt of gratitude from the software virtuosos and inspiring people that I met there.<br />
At this time I really feel like dropping names. If nothing else then just for the reason that these guys are inspiring and should get some praise. I hope you don&#8217;t mind <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a href="http://www.librador.com">Martin Vilcans</a> who unknowingly inspired me, and probably many more, to teach at <em>HiCollege</em>.<br />
<a href="https://plus.google.com/114693010508964299446/posts">Ivar Gaitan</a> as another code and challenge seeker who had visions and shared them with me<br />
And finally <a href="http://mannefagerlind.wordpress.com/">Manne Fagerlind</a> who opened up the world of code quality and who showed us all that testing was inseparable to software development.</p>
<p>If you work in Sweden in the Stockholm area then maybe you will get lucky and come across these three.  If you do, pay heed &#8211; you might just learn something!<br />
<strong>OK</strong> I better stop now with the<strong> flattering </strong>or it will just be too much brown nosing<strong>.</strong> I only mention a few but seriously both at HiQ and at assignments I met so many ingenious people that all made huge impressions, inspired and taught me about software.</p>
<p>OK, after this <em>Oscar-feel-nominee</em> list it is time to continue&#8230; I am way off the subject, if there ever was one.</p>
<h2 style="padding-left:30px;"><span style="color:#888888;"><em>The Great Colleague Buddy Gurarantee</em></span></h2>
<p>I learned some important lessons from my four years at HiQ. Apart from being able to immerse myself in C++, dabbling in other languages (Java, C#, Python), design principles, patterns, anti-patterns awareness, agile methodology and just having lot and lots of fun I had some very important recruiting experiences. From past experiences in Sweden I would say that normally the job-interviewing is a two step process.</p>
<ol>
<li>A manager and a team leader or engineer will meet you for an interview. If you pass you get to step</li>
<li>Two managers meet you. This time some more exploratory questions and finally the salary discussion takes place. In the end it is the managers that not only is <em>leading</em> the whole interview process but also have the final say.</li>
</ol>
<p>At HiQ it was also (usually) a two-or-three step process, but <em>upside-down</em>. First a group manager or two would meet the candidate. If the lucky candidate managed to get through the<em> eye-of-the-needle</em> then the most important step would come. The <em>colleague evaluation</em>!</p>
<p>It really is a simple concept. <em>Only</em> hire someone you would like to have as a colleague yourself. Not who the manager would like as a colleague, but who the other consultants would like to work with. From a number of interviews that I helped out with I can summarize it as following</p>
<p style="padding-left:30px;">Two consultants, potential colleagues, will sit down and talk with the nervous applicant. Sometimes testing his/her knowledge and sometimes only doing some relaxed talking about whatever,. but I think usually a mix of the two. In the end it is what the two potential colleagues thought of the applicant that mattered. Their decision was usually adhered to, and a <strong>no</strong> from them was always <strong>absolute</strong>. The colleagues had veto power and they used it carefully.</p>
<p>This is such an improvement from the <em>manager-only</em>-<em>deciding</em> interview process that I have seen at other companies. I believe that a lot of HiQ&#8217;s success is connected to their job-interview process and how it gives some kind of<br />
<strong><em>Great Colleague Buddy Guarantee</em></strong>.</p>
<p>I think the order of steps is also important: step 1 manager, step 2 potential colleagues. The manager can weed out by experience. The consultant employees can use gut feeling, tests or whatever to grasp the <em>what</em> and <em>who</em> about the candidate. The manager(s) only let through the most promising applicants and only a few are selected for consultant interviewing. This made the consultants doing the second interview feel that it was important what they were doing. It <strong>was important</strong> of course. Doing the second and not the first interview also made it more interesting for the interviewers since anyone up for a second interview was bound to have skills, personality and a story &#8230; (<em>well an interesting background</em>). In short someone that would be nice to have as a colleague.</p>
<p>The bonus of this interview process is maybe already clear to you. Employees with a certain type of personality and passion for what they do will most likely pick candidates that have personalities that fit in and who share similar passion. They would also veto out the candidates that are not just <em>felt </em>the way they  should feel, even if that candidate would have all the necessary know-how.  Gut feeling, first impression and knowledge<em>. </em>These tools can build you an employee workforce that is unstoppable. They can achieve anything because they have vital strengths in common, they share a passion for what they do and they enjoy each others company.</p>
<p>This is also a risk of course. If you manage to build a formidable workforce like the one described above you will also risk that they at some point break away to form their own companies &#8211; maybe even persuading other people to join them as they leave. Then again, it might not be a bad thing. As these people leave they might just continue to be ambassadors and continue to talk well about the company.<br />
<span style="color:#888888;"><em>Judging from what I just wrote above that is sure true of me.</em></span></p>
<h3><span style="color:#888888;"><em>Hmmm. &#8220;Gut feeling, first impression and knowledge&#8221;</em></span><br />
<em><span style="color:#888888;">Come to think of it, maybe in 2001 that was what stopped me from being a web developer,. then again if only fly fishing and golfing were the qualifying criteria then I was probably better off somewhere else<br />
&#8230;</span></em><em></em></h3>
<p>Hey. Did you apply to HiQ and did not get the job? Sorry if I bummed you out.  If you have applied to HiQ and did not get hired then I am not saying that you do not have a passion for software. Or lack of a winning personality. Heck, you are probably a coder virtuoso that love code like Romeo loved Juliette, dream, sleep, eat and sh*t software like no one else. You probably have a personality and attitude that shine like the sun and would put all others to shame if we even compared us to you&#8230; <strong>Please</strong> know that just as with everything else there are<strong> false negatives</strong> that can stop the most suitable candidate. People will have off-days, the moon, girlfriend or too much lactose intake can affect a very human process.</p>
<p>Either way, from my personal experience, this is the best way I have come across to get the employees that are just awesome.</p>
<p>Or maybe this is just common practice everywhere? I think Google<a href="http://steve-yegge.blogspot.com/2008/03/get-that-job-at-google.html?m=1"> practices something similar</a> in their rigorous 4-step hiring process. Although of course at Google you have to be exceptional not only with coding but with math, algorithm thinking in your veins and just <a href="http://en.wikipedia.org/wiki/%C3%9Cber">Über</a> at everything (including being humble, down-to-earth and not trying to show-off as <em>über</em>).<strong></strong></p>
<h2 style="padding-left:30px;"><span style="color:#888888;">Sometimes a good thing will end</span></h2>
<p>If I was professionally married to HiQ I think I started to <em>fall out of love </em>with the company. Some middle-management mishaps that affected me personally did its part and 2 hours commuting every day did not help either. I am just not a<em> jammed-traffic-waiting-to-avoid-next-crazy-driver</em> kind of guy. I will probably never <a href="http://www.imdb.com/title/tt0106856/">fall down, all D-Fens style</a> but driving all those hours in my loud <a href="http://www.honda.co.uk/cars/jazz/">Jazz</a> was wearing me down. That much commuting, never knowing if I would be<strong> 1 hour</strong>, or more, <strong>delayed</strong> due to traffic is not for me. Especially not with a kid that soon would start preschool and demanded regular drop and pick-up times.</p>
<h2 style="padding-left:30px;"><em><span style="color:#888888;">So once more it was time for a change&#8230;</span></em><br />
<span style="color:#888888;">2010, Critical and Preventive care with Medical Technology</span></h2>
<p>I wanted to make a difference also. No more military spy planes for Pakistan. <strong>Seriously</strong>.<br />
Let me say that again.<em> I would like to make a personal statement now</em>: <strong></strong></p>
<p style="padding-left:30px;"><strong><em>No more military technology assignments for me!</em><br />
</strong></p>
<p>Hey. I am not saying it is bad. I am saying <strong>I am done with it</strong>.  After the mandatory 15+ months as a 2nd Lieutenant and some 3+ years developing military technology I have done my part in this area. Especially since I feel that my karma took a big hit working with military technology&#8230; But who am I kidding really? I might have a preference but in the end it all comes down to paying the bills. At least it felt nice making that statement <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I decided <strong>medical technology was my tech field of choice</strong> for the next adventure. After a long search I decided that <a href="http://www.prevas.com/">Prevas </a>was the right choice for me. Of all the consultant companies in Uppsala they seemed to have the strongest focus on the Uppsala market. Uppsala is where I live at the moment so that was important to me. Limiting commuting time was a must. Today I do not really know how I managed to get hired by them. What made them decide to hire me? Lots of luck and maybe a beneficial job market?</p>
<p>In my attempt to keep up my salary (which was likely to be significantly lower than before), to prove that I was good at consulting I believe I came off as arrogant, egocentric and not a person I would hire myself following the previous mentioned<strong><em><br />
Great Colleague Buddy Guarantee</em></strong>. God, that just sounded terrible. I hope it was not that bad. Either way here I am. Prevas &#8211; in all its glory, from within its core it shows (<em>to me</em>) the very essence of the Swedish Software Engineer. All competent, all experienced, many senior level engineers. I look forward to getting to know Prevas and its soul and learning more about creating great software, and maybe also about myself in the process.</p>
<h2 style="padding-left:30px;"><span style="color:#888888;">2011, paternal leave for two months in the USA did wonders</span></h2>
<p>I feel rejuvenated and am boosting with energy and inspiration. My agony, obsession, emptiness and pleasure all mixed together after publishing the <a href="http://www.codeproject.com/Articles/288827/g2log-An-efficient-asynchronous-logger-using-Cplus">G2log article at codeproject</a> is finally behind me.</p>
<p>Now, back in Sweden again I look back on weeks with my in-laws when I could ponder, meditate, changing diapers and just hang out with my kids. All those hour long stroller walks while trying to get my daughter to take her <em>post-lunch</em> nap were great. All of these everyday life events while not messing around (<a href="http://ideone.com/URJWy">much</a>) with C++11, concurrency intricate designs or g2log were good. I decided to write this blog entry for once,. maybe more personal than I usually write. But that is what I really write the blog for anyway: for myself, personal record keeping and whomever else that might be reading it.</p>
<p>If I am lucky then maybe my <em>war stories</em> can help someone. Not giving up, trying harder, doing it differently, are all good life rules, at least for me and maybe also for you.</p>
<p><span style="color:#888888;">To be continued for sure  &#8230;</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/317/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=317&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2012/02/01/the-hiring-process-11-years-of-success-and-failures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>g2log &#8211; an asynchronous logging library is now live at CodeProject</title>
		<link>http://kjellkod.wordpress.com/2011/11/24/g2log-an-asynchronous-logging-library-is-now-live-at-codeproject/</link>
		<comments>http://kjellkod.wordpress.com/2011/11/24/g2log-an-asynchronous-logging-library-is-now-live-at-codeproject/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 17:17:51 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=303</guid>
		<description><![CDATA[G2log is finally live at CodeProject http://www.codeproject.com/KB/library/g2log.aspx Many thanks to the people who followed g2log and emailed me improvement suggestions. It made it a whole lot better! Apart from some formatting issues, a missing word in the introduction and that &#8230; <a href="http://kjellkod.wordpress.com/2011/11/24/g2log-an-asynchronous-logging-library-is-now-live-at-codeproject/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=303&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>G2log is finally<a title="http://www.codeproject.com/KB/library/g2log.aspx" href="http://www.codeproject.com/KB/library/g2log.aspx"> live at CodeProject</a> http://www.codeproject.com/KB/library/g2log.aspx</p>
<p>Many thanks to the people who followed g2log and emailed me improvement suggestions. It made it a whole lot better!</p>
<p>Apart from some formatting issues, a missing word in the introduction and that the downloads are only available on BitBucket and not through CodeProject I think it looks OK. Hopefully the editors will fix the rough edges in a couple of days.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/303/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=303&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/11/24/g2log-an-asynchronous-logging-library-is-now-live-at-codeproject/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>Kjellkod&#8217;s g2log vs Google&#8217;s glog:     Are asynchronous loggers taking over?</title>
		<link>http://kjellkod.wordpress.com/2011/11/17/kjellkods-g2log-vs-googles-glog-are-asynchronous-loggers-taking-over/</link>
		<comments>http://kjellkod.wordpress.com/2011/11/17/kjellkods-g2log-vs-googles-glog-are-asynchronous-loggers-taking-over/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 04:56:02 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=266</guid>
		<description><![CDATA[G2log, the asynchronous logging utility I have been working on in my spare time is finally live and ready to download. An introduction and a performance comparison with Google&#8217;s logging library (glog) can be found at www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11 The performance tests &#8230; <a href="http://kjellkod.wordpress.com/2011/11/17/kjellkods-g2log-vs-googles-glog-are-asynchronous-loggers-taking-over/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=266&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>G2log, the asynchronous logging utility I have been working on in my spare time is finally <strong>live</strong> and ready to download. An introduction and a performance comparison with Google&#8217;s logging library (glog) can be found at <a title="G2log, an asynchronous logging utility" href="http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11" target="_blank">www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11</a></p>
<p>The performance tests were made on a Dell Latitude E6500 laptop, Intel® Core™2 Duo CPU P8600 @ 2.40GHz × 2, with a <strong>solid state</strong> drive. On another system using a standard hard drive the difference between synchronous (glog) and asynchronous (g2log) would be larger.</p>
<p>The performance comparison is more about comparing the power of asynchronous operations to synchronous operations. Disk file access I/O wait times can be painfully long. This is clearly helped if done asynchronously, and punished if done synchronously</p>
<p>In a worst case scenario with a lot of data congestion the Google&#8217;s glog shows wait times of 1/2 second up to a whole second when flushing log entries to disk.</p>
<p>Kjellkod&#8217;s g2log gets leverage by doing slow disk access in the background. With the same worst case test setup the maximum wait times for a LOG call to finish was in the range of 13 &#8211; 113 milliseconds.</p>
<p>In a not so extreme test, but still with heavy LOG usage (1 thread writing 1 million log entries) g2log has maximum wait times of about 13 milliseconds. Google&#8217;s glog peaks at 459 milliseconds.</p>
<p>With these high times it can be good to know that the average time for a LOG call was much better. For g2log the average time was in the range of 6 &#8211; 9 microseconds.</p>
<p>For Google&#8217;s glog the average time was in the range of 10 &#8211; 13 microseconds. The log entries <em>buffering</em> that makes glog <a href="https://sites.google.com/site/kjellhedstrom2/g2log-efficient-background-io-processign-with-c11/g2log-vs-google-s-glog-performance-comparison#TOC-Simplified-description-of-Pseudo-As"><em>pseudo asynchronous</em></a> clearly pays off. Google&#8217;s glog still achieves very good average time for being a synchronous logger.</p>
<p>From <a href="http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11/g2log-vs-google-s-glog-performance-comparison" target="_blank">my testing</a> it is obvious that an asynchronous logging utility  outperforms a synchronous logger. Especially the peak wait times, when doing slow disk access, is mitigated if done in the background.</p>
<p>In addition to outperforming the traditional synchronous loggers g2log also provides some <em>crash security</em>. At shutdown g2log flushes all FIFO queued log entries to file. </p>
<p>In case of a <strong>fatal event</strong>, such as segmentation fault or floating point exception (and more), a signal handler will receive the <em>fatal signal</em> then notify g2log, which resends the aborting signal <strong>after</strong> saving to file all the pre-fatal log entries. The resent fatal signal will finally abort the application.</p>
<p>Too see how it is done, and to start using g2log you can go to <a href="http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11" target="_blank">http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11</a>. </p>
<p>G2log&#8217;s code is completely free, available as a <em>Public Domain Dedication</em>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/266/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=266&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/11/17/kjellkods-g2log-vs-googles-glog-are-asynchronous-loggers-taking-over/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>Active Object the C++11 way</title>
		<link>http://kjellkod.wordpress.com/2011/11/08/active-obbject-the-c11-way/</link>
		<comments>http://kjellkod.wordpress.com/2011/11/08/active-obbject-the-c11-way/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 20:10:56 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Active Object]]></category>
		<category><![CDATA[C++11]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/2011/11/08/active-obbject-the-c11-way/</guid>
		<description><![CDATA[g2log is getting close to being finished (as in an online article somewhere). While that is taking place I took a side step and cleaned up some old code snippets / articles that I wrote at kjellkod.cc I think the &#8230; <a href="http://kjellkod.wordpress.com/2011/11/08/active-obbject-the-c11-way/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=258&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a title="g2log, asynchronous logging with C++11" href="http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11" target="_blank">g2log</a> is getting close to being finished (as in an online article somewhere). While that is taking place I took a side step and cleaned up some old code snippets / articles that I wrote at <a title="KjellKod.cc" href="http://www.kjellkod.cc/kjellkod-code" target="_blank">kjellkod.cc</a></p>
<p>I think the best one, at least the easiest read,  so far is &#8220;<a title="Active Object the C++11 way" href="http://www.kjellkod.cc/active-object-with-cpp0x" target="_blank">Active Object the C++11 way</a>&#8220;.  It was previously named &#8220;&#8230; C++0x way&#8221;.</p>
<p>I put this stuff up mostly because I think it&#8217;s fun, but once in a blue moon I get an email from someone who is using this, or another snipped and just wanted to say thanks. Those days I just get a big mental reward and a silly smile.</p>
<p>It&#8217;s nice to make a difference.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=258&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/11/08/active-obbject-the-c11-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>Elements of Modern C++ Style</title>
		<link>http://kjellkod.wordpress.com/2011/10/29/elements-of-modern-c-style/</link>
		<comments>http://kjellkod.wordpress.com/2011/10/29/elements-of-modern-c-style/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 07:13:11 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C++11]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=252</guid>
		<description><![CDATA[Elements of Modern C++ Style. This is good, quick online help when starting out with C++11. I&#8217;m sure to look over this and of course Bjarne Stroustrup&#8217;s more in depth C++11FAQ as g2log moves closer to being released.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=252&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href='http://wp.me/Peb5Y-ch'>Elements of Modern C++ Style</a>.</p>
<p>This is good, quick online help when starting out with C++11. </p>
<p>I&#8217;m sure to look over this and of course Bjarne Stroustrup&#8217;s more in depth C++11<a href="http://www2.research.att.com/~bs/C++0xFAQ.html#what-features">FAQ</a> as <a href='http://kjellkod.cc/g2log-efficient-background-io-processign-with-c11'>g2log</a> moves closer to being released.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/252/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=252&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/10/29/elements-of-modern-c-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>My Deadly version of Tag</title>
		<link>http://kjellkod.wordpress.com/2011/09/21/my-deadly-version-of-tag/</link>
		<comments>http://kjellkod.wordpress.com/2011/09/21/my-deadly-version-of-tag/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 11:50:45 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[Hunting]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=183</guid>
		<description><![CDATA[Alternative title: (Moose) Stalking, am I THAT good at it? &#8230; But seriously what is the use if I cannot see? Several days now into the September moose hunt in Northern Sweden. Our elkhound Aslan is on &#8220;vacation&#8221; with it&#8217;s &#8230; <a href="http://kjellkod.wordpress.com/2011/09/21/my-deadly-version-of-tag/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=183&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Alternative title: (Moose) Stalking, am I THAT good at it? &#8230; But seriously what is the use if I cannot see?</h1>
<p>Several days now into the September moose hunt in Northern Sweden. Our elkhound Aslan is on &#8220;vacation&#8221; with it&#8217;s owner till Friday. Outside the rain has poured down for 2 days and we&#8217;ve taken the opportunity to clear the cabin, stock up on our supplies and we&#8217;re to return before sunrise tomorrow at the cabin &#8211; mayhap it has cleared up by then?</p>
<p>Anyhow, this entry is really about a type of hunting, moose stalking, that I&#8217;m getting pretty good at, although (as you&#8217;ll read) I still have lots to learn.</p>
<p>Three days ago I was scouting out our most northern area for tracks. This is an area where we normally don&#8217;t hunt for a number of different reasons. I got surprised when I saw lots, and lots of moose tracks. A few of them fresh and with two tracks from a moose cow and it&#8217;s calf. The tracks were made this night or maybe just recently.</p>
<p>I decided to stalk them and got lucky, or well, almost. The moose tracks were relatively easy to follow. The tracks went alongside a tiny path in the forest, making sneaking easy as it was less brush to stay clear of and also making the prints of the moose easier to spot. 1 hour and 45 minutes later I had followed them for approximately 1 km. In front of me was trickier terrain, I could continue on the path but had to dodge 4 trees with low branches that went over the path, or I could walk around the trees but the high brush would also make that much slower and increase the possibilities for mistakes. I decided to dodge the branches.</p>
<p>The first tree went just fine. Some 17 years of martial arts have helped my balance and some ridiculous slow acrobatics moved me over a tiny spruce, under and sideways of some branches until I was in the clear. I took my time and surveyed the surroundings. Up ahead I could see the clearing, a bog, that I was expecting. I had planned to stay put at the clearing for 20 minutes and then head back again since the sun has started to get low.</p>
<p>I guess I was too focused on the clearing and if any moose was grazing far ahead. I just completely missed what was almost in front of me. Just to the side of the next trees to dodge, behind a thin spruce was a moose cow. A sudden, but not too sudden movement of gray alerted me. I froze in place. I heard the calf up ahead. Had they heard me? Had they seen me? The cow had been <strong>very</strong> close, <strong>ludicrously</strong> <strong>close</strong> even. I was hoping they they hadn&#8217;t but my mind was a blank. I did not try to go through, or sidestep the spruces I only waited for them to show up on either side.</p>
<p>After what felt like an eternity, but was probably just a couple of minutes. I heard the brush rustle as they moved away. Maybe a trick of the wind had given them my scent? Or maybe they were just moving away. Either way they had stayed for those minutes, just beyond the spruces and close enough for me to act on, if my mind would&#8217;ve worked&#8230;</p>
<p>I moved up and checked out the area. Yes, it was the moose and the calf that I had tracked. No doubt about it.</p>
<p>I went back to where I had stood and measured with steps the distance from my position to where the moose cow had hidden. It was a distance of 12 steps. 12 steps! That would be approximately (for me) 10 meters or 33 feet. Amazing. And I missed it.</p>
<p>The next day I just had to return. I measured the steps again. Checked the tracks and took a picture with my IPhone. Of course in the morning light it looks impossible to miss a huge moose behind the thin spruce (just left of the center). Use your imagination,. the trees to the right of it was casting a dark shadow. As the moose was in the deep shade and hard to see I still think it was short of a miracle that I missed it. Funny, Crazy, Sad and Unbelieving.</p>
<p><a href="http://kjellkod.files.wordpress.com/2011/09/12-step-moose-hiding1.jpg"><img title="12-step-moose-hiding" src="http://kjellkod.files.wordpress.com/2011/09/12-step-moose-hiding1.jpg?w=640&#038;h=478" alt="" width="640" height="478" /></a></p>
<p>I know that hunters often come very close to moose. Usually when dogs are involved and the moose is on the move they can almost run over the hunter. So 10 meters away isn&#8217;t remarkable that way. However, 10 meters away, when walking straight at the moose THAT my friend is remarkable. The closest I got before was 25-30 meters, but then I knew the moose was there, now I didn&#8217;t and was just trying to be &#8220;sneaky&#8221; (if you get my drift)</p>
<p>Tomorrow is a new day. Rain or not I&#8217;m gonna stalk the bogs, the clearings and the forest. This time &#8230;</p>
<p><strong>2011-09-25 update</strong>: Too bad the rain just kept pouring down. Of the hunting days all of 4+ days just rained away. <span style="text-decoration:underline;">160</span>mm of rain in 4+ days. Flooded swamps, roads and just very, very wet. At least I got a good last day. Tracking a bull moose for almost 4km,. then he made a semi-circle and if I would&#8217;ve continued he would&#8217;ve gotten wind of me so this year (so far) no moose meat in the freezer. But in 10 days I go hunting again <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-183"></span></p>
<p>&nbsp;</p>
<p>&#8230;</p>
<p><strong>So how do I do moose stalking?</strong> Below I&#8217;ve written down my ideas how I do the moose stalking. I&#8217;m sure I&#8217;ve lots to learn but it seems to be going quite OK.</p>
<p>Stalking is painstakingly slow. Apart from the wind catching your scent and signaling the moose the animal also has great hearing and although it has pretty bad eyesight it&#8217;s still good at spotting movement . So for a successful stalk you need to basically have the wind in your favor, being virtually completely silent and moving so slow that even if the moose looks at you it won&#8217;t easily see your movement.</p>
<p>This type of stalking is something I&#8217;ve practiced the last 4 years I&#8217;ve been hunting. My neighbor told me how he hunts and inspired me, hopefully I&#8217;ve even stepped it up a notch. Basically it&#8217;s very, very, very slow moving. Each step being placed carefully, slow, deliberately with a precise shifting of my weight on the next foot. This way you can stop mid-motion in case there&#8217;s a hidden branch under your foot that you missed &#8211; you can change the placing of the step and avoid a disastrous &#8220;crack&#8221; that would alert the prey.</p>
<p>Every 10 steps or so, or whenever the terrain is suitable I slowly lower myself so that I can see under the branches, getting a different look at your surroundings is important.</p>
<p>Every now and then, say 30 steps or whenever suitable I just freeze in place. Take in the forest sounds even more and try to penetrate visually what&#8217;s beyond the spruces.</p>
<p>Of course moose have a sense of hearing that is just short of incredible. They can move their ears in any direction without moving their head which helps them pinpoint very accurate where a sound comes from. So how do I avoid getting noticed by sound? Well, I use &#8220;active hearing protection&#8221; (see <a href="http://www.jakto.se/fileArchive/produktbilder/nya_bilder/horselskydd/!600x600/!peltor_tactical_xp.jpg">image</a> of a similar product) with this I can magnify sound a lot (I think approx. 17-18dB). This is great for hearing animals in the forest but above all it makes it very obvious <strong>how much sound I make</strong>.</p>
<p>By magnifying all the sounds nearest. i.e. my sounds I can really hear the rustling of my clothes, the sound of a tree branch sweeping across my pants or the crushing of a leaf under the boot. This will make you learn very fast to control your movements until the sounds you make are less than the natural sounds of the forest.</p>
<p>What about mistakes? Yes. They do happen, but by taking care and following the advice above they should be minimized. When a mistake happens, a twig cracks, or you *whatever* &#8230; then the solution is simple. Just freeze in place. One sound is no sound. After all the forest is full of sounds, it&#8217;s only when consecutive sounds (mistakes) come from you that the animal will react.</p>
<p>By using this tactic I have successfully (knock-on-wood) being able to sneak close to moose, spotting them and moving closer &#8211; hopefully for a killing shot- 3 out of 4 years (this hunt is still ongoing,. and I guess it&#8217;s debatable whether or not I managed it so far this year &#8212; top section)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/183/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=183&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/09/21/my-deadly-version-of-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>

		<media:content url="http://kjellkod.files.wordpress.com/2011/09/12-step-moose-hiding1.jpg" medium="image">
			<media:title type="html">12-step-moose-hiding</media:title>
		</media:content>
	</item>
		<item>
		<title>Enter Cilk Plus</title>
		<link>http://kjellkod.wordpress.com/2011/09/16/enter-cilk-plus/</link>
		<comments>http://kjellkod.wordpress.com/2011/09/16/enter-cilk-plus/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 10:34:12 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=168</guid>
		<description><![CDATA[It was an interesting day yesterday. 10 hours on the road from Kista all the way up north to Luleå for the annual moose hunt. With my Honda Jazz, not really built for highways, the radio Bandit FM blaring in &#8230; <a href="http://kjellkod.wordpress.com/2011/09/16/enter-cilk-plus/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=168&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It was an interesting day yesterday. 10 hours on the road from Kista all the way up north to Luleå for the annual moose hunt. With my Honda Jazz, not really built for highways, the radio <a href="http://webradio.bandit.se/webbradio/webbradio-bandit.php">Bandit FM</a> blaring in the speakers and with the mornings Cilk Plus Keynote lectures from <a href="http://www.sics.se/multicore2011">SICS multicore days</a> still being processed I was more than a little tired when I finally arrived.</p>
<p>The Cilk plus seems very promising. Intel bought up the Cilk Arts company and is working now towards fully commercializing it , for now free as a &#8220;<a href="http://software.intel.com/en-us/articles/intel-cilk-plus-software-development-kit/">technology preview</a>&#8221; &#8212; and maybe more in focusing on getting the revenues from the Cilk behind the curtains technology such as CilkScreen that guarantees to find <a href="http://software.intel.com/en-us/articles/are-determinacy-race-bugs-lurking-in-your-multicore-application/">the parallel code determinacy races</a>.</p>
<p>In short Cilk Plus provides an <strong>easy</strong> way for the programmer to expose the parallelism. This used to be most used, and most efficient for library writers, low lewel, embedded type of optimization. But now since Intel is stepping it up a notch and is really promoting Cilk Plus and especially its many advantages to OpenMP I believe Cilk Plus has a real chance in making it into the application software as well.</p>
<p>A word about Cilk Plus vs OpenMP. OpenMP is an open standard so to compete with that Intel has made Cilk Plus <strong><a href="http://software.intel.com/en-us/articles/contribute-to-intel-cilk-plus/">open</a></strong> as well and welcome other compiler vendors to implement it. In fact it&#8217;s well in progress for GCC and a patch to support the most important Cilk features was released as a <a href="http://software.intel.com/en-us/forums/showthread.php?t=85266">GCC 4.7 patch this Augus</a>t. Cilk Plus also scaled much better than OpenMP and does not penalize other processes as OpenMP does.</p>
<p>Two affiliates with Intel was at <a href="http://www.sics.se/multicore2011">SICS Multicore Days</a> to promote Cilk plus. Dr. Arch Robinson from Intel who showed practical easy-to-use programming examples (here&#8217;s his <a href="http://software.intel.com/en-us/blogs/2010/09/13/thread-parallelism-using-cilk-notation-for-cc/">cilk plus blog series</a> and Intel <a href="http://software.intel.com/en-us/blogs/tag/cilk-plus/">blogs for Cilk Plus</a>). And the Cilk Plus keynote from Professor Charles E Leiserson from MIT (a Cilk founder). I don&#8217;t think the multicore days presentations are available yet but I found this presentation that was borrowed from Charles&#8217; lecture and it seems to be almost the same: <a href="http://developer.amd.com/afds/assets/presentations/2080_final.pdf">http://developer.amd.com/afds/assets/presentations/2080_final.pdf</a></p>
<p>Let&#8217;s cut to the chase let&#8217;s see a classic simple example of Cilk Plus. The example is the fibonacci calculation as <a href="http://www.ckluk.org/ck/talks/cilkplus-tutorial-ppopp11.pdf">shown in this Intel presentation</a>.</p>
<pre>int fib(int n)
{
   if (n &lt; 2) return n;
   int x = fib(n-1);
   int y = fib(n-2);
return x+y;
}</pre>
<p>Which with nested parallelism would look like this</p>
<pre>int fib(int n)
{
   if (n &lt; 2) return n;
   int x = <strong><span style="color:#ff0000;">cilk_spawn</span></strong> fib(n-1);
   int y = fib(n-2);
<strong><span style="color:#ff0000;"> cilk_sync;</span></strong>
  return x+y;</pre>
<p>Another nice feature is the <strong><span style="color:#ff0000;"> cilk_for</span></strong> that for array and matrix operations many times can replace the normal for-loop. At scope end the cilk_for will synchronize the parallel calls. This is implied implicitly and can also, as shown above, be forced wherever with cilk_sync</p>
<p>Here&#8217;s another view of Cilk Plus from <a href="http://drdobbs.com/architecture-and-design/231400279">Dr.Dobb</a>, unfortunately it does not describe CilkScreen which I think goes with Cilk Plus as hand-in-glove <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As soon as the moose hunt is done with I&#8217;m sure to check out Cilk Plus <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=168&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/09/16/enter-cilk-plus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
		<item>
		<title>Moving to Qt5? Will that remove Qt&#8217;s performance issues on Linux?</title>
		<link>http://kjellkod.wordpress.com/2011/05/22/moving-to-qt5-will-that-remove-qts-performance-issues-on-linux/</link>
		<comments>http://kjellkod.wordpress.com/2011/05/22/moving-to-qt5-will-that-remove-qts-performance-issues-on-linux/#comments</comments>
		<pubDate>Sun, 22 May 2011 10:37:37 +0000</pubDate>
		<dc:creator>kjellkod</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://kjellkod.wordpress.com/?p=140</guid>
		<description><![CDATA[The last year and a half I&#8217;ve immersed myself with Qt, both for comparison reasons with other graphical frameworks and lately with hands-on system development. It&#8217;s been fun and I really like how easy Qt allows you to create widgets &#8230; <a href="http://kjellkod.wordpress.com/2011/05/22/moving-to-qt5-will-that-remove-qts-performance-issues-on-linux/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=140&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The last year and a half I&#8217;ve immersed myself with Qt, both for comparison reasons with other graphical frameworks and lately with hands-on system development. It&#8217;s been fun and I really like how easy Qt allows you to create widgets and GUI with your own look-and-feel.</p>
<p>Today I read a somewhat dated <a href="http://labs.qt.nokia.com/2011/05/09/thoughts-about-qt-5/">post regarding the coming Qt5</a> which is the next big Qt API change. The move from Qt3 to Qt4 was <strong>huge</strong> and it wasn&#8217;t done in a snap to convert Qt3 made software to Qt4 &#8211; but this time seems that most of the API:s will stay intact. So I hope that Qt4 based software can do this transaction without too much headache for the programmers.</p>
<p>With Qt5 the Qt Quick technology is definitely put in focus. As Qt Quick is a web development inspired technology GUI and widget making should get easier and faster. But the change of focus from Qt/C++ to Qt/Quick might not be altogether positive. I see a trend that companies are choosing not to adopt to the Qt Quick technology for a few different reasons.</p>
<p>1. Transparency. In Qt/C++ most *magic* behind the curtains can be crystal clear with just a small effort on the developer&#8217;s side. If problems occur you can debug your way into the C++ core of Qt itself. With the Javascript-ish QML that transparency is gone or at least muddled thanks to the extra layers for handling QML.</p>
<p>2. Performance. Already today Qt is suffering from performance issues. Putting QML on top befuddles even more the reason why some operations are sluggish. It&#8217;ll make it much harder to see if it&#8217;s the Qt/C++ part or the QML part that&#8217;s the culprit.</p>
<p>Already now it&#8217;s pretty darn hard to find out these things, especially when you throw in graphic driver dependencies as well.<br />
&#8230;</p>
<p>Let me give you an example of the performance issues I&#8217;ve seen with Qt. Maybe this is actually the core of today&#8217;s blog:</p>
<p>Especially with the native graphical engine on Linux-types of OS:es can Qts performance issues be manifested. This is evident on <strong>Intel&#8217;s Atom platforms with integrated graphical chips</strong>.</p>
<p>Inte&#8217;s drivers should support all the necessary bells and whistles but even standard 2D rendering operations are sluggish with X using up most of the CPU resources. This is very easy to verify with Qt&#8217;s example software &#8220;<a href="http://doc.qt.nokia.com/main-snapshot/painting-concentriccircles.html">concentric circles</a>&#8220;.</p>
<p>Use the native graphical engine, hack the concentriccircles example so it runs 10.000 &#8220;circle operations&#8221; and measure the time for this. Then run the same concentriccirles example but this time with the runtime flag for using Qt&#8217;s <em>raster</em> graphical engine. With <span style="color:#0000ff;">-graphicssystem raster</span> the graphics will be software (Qt) rendered  and not through X11/Intels drivers. All of a sudden, by bypassing the Inte&#8217;s drivers the rendering performance gets a boost. On three different Intel Atom Linux projects I&#8217;ve heard about, or worked with firsthand the difference was in the area of 80% X11/CPU utilization (native) vs 2-4% X11/CPU utilization (raster).</p>
<p>Here Qt probably says it&#8217;s Intels driver&#8217;s fault, where Intel blames it on Qt&#8217;s lack of OpenVG support. The solution is however easy, no matter whose fault it is. Just use <em></em><span style="color:#0000ff;">-graphicssystem raster</span> and your system should work great.</p>
<p>According to testing of Qt and communication with Intel I&#8217;ve gleaned the following.</p>
<p><span style="color:#0000ff;">-graphicssystem raster</span> works great. Low CPU overhead and high speed for most (all) operations. Software rendering is done in the Qt libraries (?) instead at the driver.</p>
<p><span style="color:#0000ff;">-graphicssystem native</span> (the default) will make your Linux ( in case of Intel Atom with integrated graphical chip) very sluggish due to the CPU (X11) overhead.The fault of this is according to Intel how Qt approximates a sine wave using the native X calls. This is highly inefficient and resulting in a multitude of extra calls into the Intel driver for creating/deleting pixmaps and drawing trapezoids.</p>
<p>Whether this is true or not I&#8217;ve not even tried to confirm. I know that raster works so that is my recommendation to go with. A few years ago (2009?) raster wasn&#8217;t <strong>that</strong> stable but I hope it is now. However it might be for good reasons that the <em>trolls</em> haven&#8217;t made <em>raster</em> the default on X11, so who knows there might be other pitfalls when using <em>raster </em>that I do not know about.</p>
<p>I guess my blog lost focus a bit. My point being. Adding a new layer on top of Qt for the GUI work can be great for decreasing developing time. But this will definitely come at a cost whenever the software engineers doing the work run into performance issues &#8211; are those issues due to Qt or QML? In the end, if these issues occur or cannot be understood or worked around it may be a show stopper for the project! forcing the project to switch graphical technology or hardware altogether.</p>
<p>I guess I&#8217;ll have &#8220;fun&#8221; debugging tasks in a year or so <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kjellkod.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kjellkod.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kjellkod.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kjellkod.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kjellkod.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kjellkod.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kjellkod.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kjellkod.wordpress.com/140/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kjellkod.wordpress.com&amp;blog=15467684&amp;post=140&amp;subd=kjellkod&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kjellkod.wordpress.com/2011/05/22/moving-to-qt5-will-that-remove-qts-performance-issues-on-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba3dff2713f82030e7f0fcbd719325a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjellkod</media:title>
		</media:content>
	</item>
	</channel>
</rss>
