Category Archives: Optimization

Condition variables performance of boost, Win32, and the C++11 standard library

About four years ago, I wrote the condition variables in Win32 API was much faster than boost threading library implementation. Since then the boost threading library has been rewritten and C++11 has introduced the threading support in the standard library. … Continue reading

Posted in C++, Optimization | Tagged , , | 1 Comment

Use IO Completion port to implement thread safe FIFO

Here is an example to implement thread safe FIFO using IO Completion port as a queue implementation. The implementation assumes there is only on thread pushing and another thread pulling. /*! A thread safe FIFO object with single thread push … Continue reading

Posted in Optimization | 1 Comment

Win32 native monitor is much faster than boost

Windows Vista (finally!) introduced APIs to build a monitor object.http://msdn2.microsoft.com/en-us/library/ms683469.aspx So, how’s performance? Let’s benchmark it. I wrote two bounded FIFO classes. One was based on boost threading library (http://www.boost.org/doc/html/thread.html) and the other was based on the new Win32 APIs. … Continue reading

Posted in Optimization | 1 Comment

Non-alignment integer access performance

When you define a structure like this, the integer field is allocated not just after the byte field, but aligned to 4 byte boundary. struct foo{  unsigned char v1;  unsigned int v2;}; It’s because x86 architecture has a performance issue … Continue reading

Posted in Optimization | 2 Comments

Optimization with C++ Template

C++ template can be used for enabling optimization. For example, you have a function: void foo(int x){ // … int v = n / x; // slow division operation // … } And call it. foo(16); Let’s assume foo is … Continue reading

Posted in Optimization | Leave a comment