Archive
Vector Performance
std::vector, or built-in array, THAT is the question – Unshakenspeare
In C++, all post-beginner programmers know about the performance vs. maintainability tradeoff regarding std::vector and built-in arrays. Because they’re less abstract and closer to the “metal“, read/write operations on arrays are faster. However, unlike a std::vector container, which stores its size cohesively with its contents, every time an array is passed around via function calls, the size of the array must also be explicitly passed with the “pointer” – lest the callees loop themselves into never never land cuz they don’t know how many elements reside within the array (I hate when that happens!).
To decide which type to use in the critical execution path on the project that I’m currently working on, I whipped up a little test program (available here) to measure the vector/array performance difference on the gcc/linux/intel platform that we’re developing on. Here are the results – which consistently show a 60% degradation in performance when a std:vector is used instead of a built-in array. I thought it would be lower. Bummer.
But wait! I ain’t done yet. After discovering that I was compiling with the optimizer turned off (-O0), I rebuilt and re-ran with -O3. Here are the results:
Unlike the -O0 test runs, in which the measured performance difference was virtually independent of the number of elements stored within the container, the performance degradation of std::vector decreases as the container size increases. Hell, for the 10K element, 1M loop run, the performance of std::vector was actually 2% higher than the plain ole array. I’ve deduced that std::vector::operator[] is inlined, but when the optimizer is turned “off“, the inlining isn’t performed and the function call overhead is incurred for each elemental access.
If you’re so inclined, please try this experiment at home and report your results back here.
Red State
Yesterday, I rented and watched the latest Kevin Smith movie on YouTube. “Red State” is a well written, well acted, well crafted, and wild cinematic ride that’s way different from any of Mr. Smith’s previous movies.
Created with a miserly budget (like all of his movies) of $5M and distributed by Kevin himself, it stars John Goodman, (Oscar winner) Melissa Leo, Stephen “Office Space” Root, and Michael Parks. Oh, and Kevin Pollak makes a short but memorable appearance and disappearance in the flick. D’oh!
The movie’s plot revolves around the psychopathic deeds “executed” by a god-fearing religious cult and the incompetent hypocrisy of the US ATF in bringing down this “terrorist cell“. Mr. Parks gives a riveting and Oscar worthy performance as the calm and cool psycho-patriarch of the “pure” christian sect.
As is custom, Kevin’s script contains some funny one-liners interwoven with some seriously biting dialog. There are also several shocking “holy shit!” scenes that come out of nowhere to keep you on the edge of your seat and highly engaged with the medium. Fer sure, it’s one of the best movies I’ve seen this year. You should see it too.
Note: I have no idea if the fictional town of “Cooper’s Dell” resides in the great state of Texas. It’s just the first state that came to mind when I started to compose the dorky BD00 graphic for this post. Hee Haw!
Something’s Uh Foot?
It’s my understanding that the financial crisis was precipitated by the concoction of exotic investment instruments like derivatives and derivatives of derivatives that not even quantum physicists could understand.
Well, it looks like the shenanigans may not be over. Take a look at this sampling of astronomically high paying jobs from LinkedIn.com for C++ programmers:
Did the financial industry learn a lesson from the global debacle, or was it back to business as usual when the dust settled? Hell, I don’t know. That’s why I’m askin’ you.
Devilbert
Fuzzy And Clear
The higher one ascends up the corpo ladder, the fuzzier one’s view becomes regarding how the enterprise works and what mania takes place down in the boiler rooms. On the other hand, who reports to whom becomes clearer and clearer and perversely more important than nurturing continuous improvement and innovation. These effects can be called “losing touch with reality” and “perverse inversion of importance“.
90 Degree Rotation
The figure below shows a 3 group system that efficiently transforms a stream of raw inputs into a stream of valued outputs (they’re valued because customers want to pay for them) via the application of talent, knowledge, and skill. In this system, since all groups are on the same horizontal plane of importance, negative feedback channels are embraced, and hence, the information that flows within them blunts the rate of increase in entropy while providing a source of reflective learning.
Now, let’s introduce vertical levels of “perceived importance” by rotating the system in the clockwise direction by 90 degrees:
So, you ask “why were those red verboten x’s introduced during the rotation? “. I put them there because once people start perceiving that the levels above are more important than them, they stop giving negative feedback – even when the inputs they’re given to work with turn into POPs over time. After all, if someone/group is perceived as more important than someone else, the “someone else” is likely to think that whatever they’re given as an input to work with must be good – regardless of its real quality.
Now, let’s introduce a culture of fear (which usually goes hand-in-hand with hierarchical levels of importance) into the system:
So, you ask “why were those feedback loops to “self” crossed out? “. You see, when a sub-group is an integral part in a fearful hierarchy of importance, it doesn’t critically evaluate its own work and it covers up mistakes – lest it be perceived as unworthy for promotion to the next higher level of importance by those in said level.
As startups grow, unless their founders exert Herculean force to prevent it, they start rotating to the right. The rate of rotation is often so sloooow that no one notices it until it’s too late . The feedback loops are broken, product/service quality erodes, and the fit hits the shan. D’oh! I hate when that happens. Don’t you?
No, I’m Argyle
When something is so over-hyped like, say, “agile“, if you try it out and don’t find it to be effective, the high priests will tell you that you’re doing it wrong. If you don’t try it out because your common sense and experience tell you it won’t work effectively in the context you’re in, then the high priests will call you a Luddite. The high priests of anything over-hyped always have their bases covered, no?
Effective But Destructive
In “I’m Feeling Lucky”: Google Employee No. 59 Tells All , Douglas Edwards tells one story about mercurial Google co-founder Larry Page:
How Larry reorganized the engineering department, for example. He didn’t like the fact that project managers were getting between him and engineers, so he called a meeting and told them very publicly that he didn’t need them–.
I’ll assert that in lots of companies, the reverse is true. In those that are DYSCOs and CLORGs, head cheeses don’t care to understand what goes on down in the boiler rooms and they desperately need project managers to tell them what’s going on. The funny part is that the project managers most likely don’t know either. D’oh!
There’s a second part to this post and the message is at the tail end of the full version of Mr. Edwards’s quote:
How Larry reorganized the engineering department, for example. He didn’t like the fact that project managers were getting between him and engineers, so he called a meeting and told them very publicly that he didn’t need them–and those people felt humiliated. I think Larry took a lesson from that, and I think he became more adept over time at managing. A young startup entrepreneur might share some of the characteristics of Larry. “If there’s a problem, reboot, fix it, move on.” That can be effective but can also be destructive. It can tear down relationships.
A Rough Cut
I think I’ve stated it before, but in case I haven’t, I’m a subscriber of safaribooksonline.com. One of the membership benefits is called “Rough Cuts“. You’re given access to book manuscripts as they are developed, before they are published. One of the rough cuts that caught my eye is titled:
Here is the the table of contents :
Uh, say what? There’s no Part I or Part IV titled “Technical Skills” in a book with “Software Architects” in the title? Gimme a break.
Granted, the book’s overview states:
“These are the skills that are typically the most challenging for people with technology backgrounds. The book assumes that the reader already has the requisite technical skills to become an architect and as such does not focus on these types of skills.”
I’m not so naive to think that “relationship, internal, and business” skills aren’t critical for success, but if you’re gonna put “Software Architects” in the title, the highly esteemed and influential BD00 demands some sort of technical skills advice in the book. You know, like heuristics and guidance for allocating requirements to functions/patterns/packages/components/class-clusters, layering for loose coupling, leveling for balanced consistency, blueprint creation through modeling, wrestling the”ilities” into submission, yada, yada, yada. But cheeze… remove the words “Software Architects” from the title.
As you might have surmised, I didn’t read the book from cover to cover – I’m simply not that into the subjects covered in it . However, I did invest an hour skimming through the chapters. If I didn’t know what the title was, I would’ve guessed that it was something like “how to be a great executive“, “X steps to managerial success“, “moving on up in the organization“, “yada, yada, yada“. There are already a bazillion books out there that offer similar content.
One saving grace is that the book uses lots of dorky, BD00-like graphics, and it has a boatload of great quotes in it. By far, my fave is this one:
Another saving grace is that the chapter in which the quote prefaces, “Passion“, is terrific. Nevertheless, I found it ironic that the rest of the book is about how to squelch your passion by acting/behaving/operating the “way you’re expected to” in order to advance your career.
Set Your Mind On Fire
One of my favorite authors on the topics of creativity and innovation, Scott Berkun, is about to hatch his fourth book: “Mindfire: Big Ideas For Curious Minds“.
Checkout the innovative way Scott is employing to launch the book: Kickstarter. Of course, I’ve signed up as a backer. Maybe you should too?
Related articles
- Need ideas: fun rewards for Mindfire book pre-orders? (scottberkun.com)
- Mindfire preorders now up – via kickstarter (scottberkun.com)
- 3 Do’s from the book “Myths of Innovation” by Scott Berkun (itsonelife.com)
















