https://meetingcpp.com/index.php/tv16/items/18.html C++ low latency coding techniques: ● General considerations C++11 Move semantics Static assert Data member layout, padding and alignment (盡量alignment access) ● False sharing http://shuyufu.blogspot.tw/2013/01/false-sharing.html ● Cache locality ● Compile-time dispatch std::sort(array, array + N, []( int a, int b) { return b < a; }); 71us, std deviation 1.5us int comparer( const void * a, const void* b) { return *(int*)a - *(int*)b; } qsort(arr, N, sizeof(int), comparer); 223us, std deviation 7us ● Constexpr C++14 feature ● Variadic templates ● Loop unrolling Generally, don’t bother, the compiler will figure it out ● Expression short-circuiting Rewrite: if (expensiveCheck() && inexpensiveCheck()) {} As: if (inexpensiveCheck() && expensiveCheck()) {} ● Signed vs unsigned comparisons 用loop iteratort用signed就是了 (可看前篇 ● Mixing float and doubles Default type of a floating...
留言
張貼留言