Category: C++
Profile : Linux -> PNG
gprof -b emv_clc2 > report.txt
gprof2dot.py report.txt > call_graph.dot
dot -Tpng call_graph.dot -o call_graph.png
Mastering Qt 5 Second Edition Notes
Speed up by ignoring std::cout
Test Code
#include <iostream>
int main(int argc, char *argv[])
{
//std::cout.setstate(std::ios_base::badbit);
for(int i = 0; i < 100; i ++) {
for(int i = 0; i < 100; i ++) {
;//std::cout << "" << std::endl;
}
}
return 0;
}
Test it without std::cout
root@imx6ul7d:~/tmp# time ./t1_1
real 0m0.041s
user 0m0.020s
sys 0m0.000s
Test it with std::cout, but redirect to /dev/null
root@imx6ul7d:~/tmp# time ./t1_0 > /dev/null
real 0m0.096s
user 0m0.030s
sys 0m0.030s
Test it with std::cout, but set io state
root@imx6ul7d:~/tmp# time ./t1_2
real 0m0.061s
user 0m0.040s
sys 0m0.000s
root@imx6ul7d:~/tmp# time ./t1_1
real 0m0.041s
user 0m0.020s
sys 0m0.000s
root@imx6ul7d:~/tmp# time ./t1_0 > /dev/null
real 0m0.096s
user 0m0.030s
sys 0m0.030s
Test it with std::cout, but set io state
root@imx6ul7d:~/tmp# time ./t1_2
real 0m0.061s
user 0m0.040s
sys 0m0.000s
root@imx6ul7d:~/tmp# time ./t1_2
real 0m0.061s
user 0m0.040s
sys 0m0.000s
Profile : Linux
Example 1
Add -pg
arm-linux-gnueabihf-g++ -Wall -g -pg hello.cpp -o hello -std=c++17
Test
[email protected]:~# gprof -b hello
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
100.00 3.45 3.45 1 3.45 3.45 hehe()
0.00 3.45 0.00 4 0.00 0.00 std::_Optional_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::_M_is_engaged() const
......
arm-linux-gnueabihf-g++ -Wall -g -pg hello.cpp -o hello -std=c++17
[email protected]:~# gprof -b hello
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
100.00 3.45 3.45 1 3.45 3.45 hehe()
0.00 3.45 0.00 4 0.00 0.00 std::_Optional_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::_M_is_engaged() const
......
Routes stream to specified buffer
Developer Command Prompt for VS 2019
cl basic_ios_rdbuf.cpp /EHsc
MSDN Source Code
#include <ios>
#include <iostream>
#include <fstream>
int main( )
{
using namespace std;
ofstream file( "rdbuf.txt" );
streambuf *x = cout.rdbuf( file.rdbuf( ) );
cout << "test" << endl; // Goes to file
cout.rdbuf(x);
cout << "test2" << endl; //normal
}