File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ Pull requests of make/cmake are welcome!
5353* [ luajit-openresty] ( https://github.com/openresty/luajit2 )
5454* [ LuaBridge] ( https://github.com/vinniefalco/LuaBridge )
5555* [ gperftools] ( https://github.com/gperftools/gperftools )
56+ * [ FlameGraph] ( https://github.com/brendangregg/FlameGraph )
5657
5758
5859* [ Awesome C++] ( https://github.com/fffaraz/awesome-cpp )
Original file line number Diff line number Diff line change 11// Copyright (c) 2020 by Chrono
22//
3- // g++ gperf.cpp -std=c++11 -lprofiler -ltcmalloc -o a.out;./a.out
4- // g++ gperf.cpp -std=c++14 -lprofiler -ltcmalloc -o a.out;./a.out
3+ // g++ gperf.cpp -std=c++14 -lprofiler -ltcmalloc -g -O0 -o a.out;./a.out
4+
5+ #include < cassert>
56
67#include < iostream>
8+ #include < memory>
9+ #include < string>
10+ #include < regex>
711
812#include < gperftools/profiler.h>
913#include < gperftools/heap-profiler.h>
1014
1115using namespace std ;
1216
17+ auto make_cpu_profiler =
18+ [](const string& filename)
19+ {
20+ ProfilerStart (filename.c_str ());
21+ ProfilerRegisterThread ();
22+
23+ return std::shared_ptr<void >(
24+ nullptr ,
25+ [](void *){
26+ ProfilerStop ();
27+ }
28+ );
29+ };
30+
31+ static
32+ auto make_regex = [](const auto & txt)
33+ {
34+ return std::regex (txt);
35+ };
36+
37+ static
38+ auto make_match = []()
39+ {
40+ return std::smatch ();
41+ };
42+
43+ void case1 ()
44+ {
45+ auto p = make_cpu_profiler (" case1.perf" );
46+
47+ auto str = " neir:automata" s;
48+
49+ for (int i = 0 ; i < 1000 ; i++) {
50+
51+ auto reg = make_regex (R"( ^(\w+)\:(\w+)$)" );
52+ auto what = make_match ();
53+
54+ assert (regex_match (str, what, reg));
55+ }
56+ }
57+
1358
1459int main ()
1560{
61+ case1 ();
62+
1663 cout << " gperf demo" << endl;
1764}
You can’t perform that action at this time.
0 commit comments