我正在尝试优化C语言中的代码,似乎一条指令占用了大约22%的时间。
该代码是使用gcc 8.2.0编译的。标志是-O3 -DNDEBUG -g和-Wall -Wextra -Weffc++ -pthread -lrt。
509529.517218 task-clock (msec) # 0.999 CPUs utilized
6,234 context-switches # 0.012 K/sec
10 cpu-migrations # 0.000 K/sec
1,305,885 page-faults # 0.003 M/sec
1,985,640,853,831 cycles # 3.897 GHz (30.76%)
1,897,574,410,921 instructions # 0.96 insn per cycle (38.46%)
229,365,727,020 branches # 450.152 M/sec (38.46%)
13,027,677,754 branch-misses # 5.68% of all branches (38.46%)
604,340,619,317 L1-dcache-loads # 1186.076 M/sec (38.46%)
47,749,307,910 L1-dcache-load-misses # 7.90% of all L1-dcache hits (38.47%)
19,724,956,845 LLC-loads …Run Code Online (Sandbox Code Playgroud) 在我没有启动的项目上工作,我想<<在一个类中添加一个运算符.问题:该类是另一个类的私有内部类,后者在一个类中namespace.
我做不到.
可以通过这种方式简化问题:
#include <iostream>
#include <map>
namespace A {
class B {
private:
typedef std::map<int, int> C;
C a;
friend std::ostream& operator<<(std::ostream& os, const C &c) {
for (C::const_iterator p = c.begin(); p != c.end(); ++p)
os << (p->first) << "->" << (p->second) << " ";
return os;
}
public:
B() {
a[13] = 10;
std::cout << a << std::endl;
}
};
}
int main() {
A::B c;
}
Run Code Online (Sandbox Code Playgroud)
我试图用编译g++ test.cpp:error: no …