Exploring C++11, part 1 (Time)

I was playing around with C++11 the other day – 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 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?

1. Time

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 (pun intended) we allways run into the task of measuring the time between two points,. and sometimes, just sometimes, it is nice to force a “wait/sleep” 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?

Continue reading

Posted in C++ | 1 Comment

The hiring process … 11 years of success and failures

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…

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.

After 11 years and a few different jobs 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.

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 – but it is long and rambling so beware if you continue to read it. You might get bored. Also this story is completely egocentric – after all it is my story.

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 Steve Yegge a blog virtuoso who is stealing way too much of my spare time since I discovered him last week

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.

Continue reading

Posted in job, rambling | 2 Comments

g2log – an asynchronous logging library is now live at CodeProject

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 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.

Posted in C++, Software Engineering | 1 Comment

Kjellkod’s g2log vs Google’s glog: Are asynchronous loggers taking over?

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’s logging library (glog) can be found at www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11

The performance tests were made on a Dell Latitude E6500 laptop, Intel® Core™2 Duo CPU P8600 @ 2.40GHz × 2, with a solid state drive. On another system using a standard hard drive the difference between synchronous (glog) and asynchronous (g2log) would be larger.

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

In a worst case scenario with a lot of data congestion the Google’s glog shows wait times of 1/2 second up to a whole second when flushing log entries to disk.

Kjellkod’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 – 113 milliseconds.

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’s glog peaks at 459 milliseconds.

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 – 9 microseconds.

For Google’s glog the average time was in the range of 10 – 13 microseconds. The log entries buffering that makes glog pseudo asynchronous clearly pays off. Google’s glog still achieves very good average time for being a synchronous logger.

From my testing 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.

In addition to outperforming the traditional synchronous loggers g2log also provides some crash security. At shutdown g2log flushes all FIFO queued log entries to file.

In case of a fatal event, such as segmentation fault or floating point exception (and more), a signal handler will receive the fatal signal then notify g2log, which resends the aborting signal after saving to file all the pre-fatal log entries. The resent fatal signal will finally abort the application.

Too see how it is done, and to start using g2log you can go to http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11.

G2log’s code is completely free, available as a Public Domain Dedication.

Posted in C++, Software Engineering | Leave a comment

Active Object the C++11 way

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 best one, at least the easiest read,  so far is “Active Object the C++11 way“.  It was previously named “… C++0x way”.

I put this stuff up mostly because I think it’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.

It’s nice to make a difference.

Posted in C++, Software Engineering | Tagged , , | Leave a comment

Elements of Modern C++ Style

Elements of Modern C++ Style.

This is good, quick online help when starting out with C++11.

I’m sure to look over this and of course Bjarne Stroustrup’s more in depth C++11FAQ as g2log moves closer to being released.

Posted in C++ | Tagged | Leave a comment

My Deadly version of Tag

Alternative title: (Moose) Stalking, am I THAT good at it? … 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 “vacation” with it’s owner till Friday. Outside the rain has poured down for 2 days and we’ve taken the opportunity to clear the cabin, stock up on our supplies and we’re to return before sunrise tomorrow at the cabin – mayhap it has cleared up by then?

Anyhow, this entry is really about a type of hunting, moose stalking, that I’m getting pretty good at, although (as you’ll read) I still have lots to learn.

Three days ago I was scouting out our most northern area for tracks. This is an area where we normally don’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’s calf. The tracks were made this night or maybe just recently.

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.

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.

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 very close, ludicrously close even. I was hoping they they hadn’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.

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’ve worked…

I moved up and checked out the area. Yes, it was the moose and the calf that I had tracked. No doubt about it.

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.

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.

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’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’t and was just trying to be “sneaky” (if you get my drift)

Tomorrow is a new day. Rain or not I’m gonna stalk the bogs, the clearings and the forest. This time …

2011-09-25 update: Too bad the rain just kept pouring down. Of the hunting days all of 4+ days just rained away. 160mm 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’ve continued he would’ve gotten wind of me so this year (so far) no moose meat in the freezer. But in 10 days I go hunting again :)

Continue reading

Posted in Hunting | Leave a comment