C++ Low level performance optimize(二)

2014-11-24 11:46:27 · 作者: · 浏览: 1
0; i < 1000000; ++i)
++f.y;
}
复制代码
假设sum_a和inc_b两个函数同事运行在不同核心的不同线程上,f的所有成员都在同一条cache line,inc_b在不听修改内存中的值,因此导致false sharing。
 
  在做性能优化前,一定要先profile,profile,profile!!!很多情况下,问题所在的位置和程序员所预期的都不一样,盲目修改代码甚至有可能降低程序性能!!!
ps:最悲剧的情况就是没有任何可靠的profile工具,还必须做性能优化,我目前的情况就是这样,怎一个惨字了得....
more refereence:
Modern C++: What You Need to Know
Native Code Performance on Modern CPUs: A Changing Landscape
Native Code Performance and Memory: The Elephant in the CPU