本文属于专栏《构建工业级QPS百万级服务》系列简介-优快云博客
性能优化,是工业应用中的重要一环。因为当我们的重要目的之一是盈利时,那么成本就十分重要。而性能优化的前提是,我们知道哪一部分功能,是最耗费资源的,才能用20%的精力去解决80%的问题。
在我使用过热点分析的工具中,最喜欢的是google profiler,因为它的信息足够详细。这里我们基于《c++11获取系统时间最快的方式》增加了3行代码,来测试这段逻辑的性能。增加代码分别是第8,51,58行
1 #include <iostream>
2 #include <chrono>
3 #include <ctime>
4 #include <sys/time.h>
5 #include <thread>
6 #include <vector>
7 #include <functional>
8 #include <gperftools/profiler.h>
9
10 using namespace std;
11 using namespace std::chrono;
12
13 const int TEST_TIMES = 1000 * 1000 * 10;
14
15 long long getCurrentTimeByClockGe