https://github.com/facontidavide/CPP_Optimizations_Diary

Rule 1:measure first

Measure first and make hypothesis later.

Linux中的 "常用 "工具是Hotspot(用于性能分析的Linux perf GUI)和Heaptrack(A heap memory profiler for Linux)。这两者就像士兵的步枪和手榴弹

https://github.com/KDAB/hotspot

https://github.com/KDE/heaptrack

一旦你知道哪个部分的代码值得优化,你可能想用Google Benchmark来测量在一个非常具体的类或函数中花费的时间。

https://github.com/google/benchmark

你甚至可以在线测试:

Quick C++ Benchmarks

Untitled

值传递

Const &

效率比值传递更高。(例外:当复制一个不需要堆分配并且小于几十个字节的对象时,没什么提升)

Move semantic(TODO)

Return value optimization(TODO)

vectors are awesome

巨大优势:元素在内存中依次紧密排列

using reserve by default

将一个元素推入一个空或满的向量时,我们需要: