MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / MemoryUsage

Function MemoryUsage

extern/re2/re2/testing/regexp_benchmark.cc:55–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void MemoryUsage() {
56 const char* regexp = "(\\d+)-(\\d+)-(\\d+)";
57 const char* text = "650-253-0001";
58 {
59 MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
60 Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
61 CHECK(re);
62 // Can't pass mc.HeapGrowth() and mc.PeakHeapGrowth() to LOG(INFO) directly,
63 // because LOG(INFO) might do a big allocation before they get evaluated.
64 fprintf(stderr, "Regexp: %7lld bytes (peak=%lld)\n",
65 mc.HeapGrowth(), mc.PeakHeapGrowth());
66 mc.Reset();
67
68 Prog* prog = re->CompileToProg(0);
69 CHECK(prog);
70 CHECK(prog->IsOnePass());
71 CHECK(prog->CanBitState());
72 fprintf(stderr, "Prog: %7lld bytes (peak=%lld)\n",
73 mc.HeapGrowth(), mc.PeakHeapGrowth());
74 mc.Reset();
75
76 StringPiece sp[4];
77 CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4));
78 fprintf(stderr, "Search: %7lld bytes (peak=%lld)\n",
79 mc.HeapGrowth(), mc.PeakHeapGrowth());
80 delete prog;
81 re->Decref();
82 }
83
84 {
85 MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
86
87 PCRE re(regexp, PCRE::UTF8);
88 fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
89 mc.HeapGrowth(), mc.PeakHeapGrowth());
90 PCRE::FullMatch(text, re);
91 fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
92 mc.HeapGrowth(), mc.PeakHeapGrowth());
93 }
94
95 {
96 MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
97
98 PCRE* re = new PCRE(regexp, PCRE::UTF8);
99 fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
100 mc.HeapGrowth(), mc.PeakHeapGrowth());
101 PCRE::FullMatch(text, *re);
102 fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
103 mc.HeapGrowth(), mc.PeakHeapGrowth());
104 delete re;
105 }
106
107 {
108 MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
109
110 RE2 re(regexp);
111 fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
112 mc.HeapGrowth(), mc.PeakHeapGrowth());

Callers

nothing calls this directly

Calls 9

ParseFunction · 0.85
HeapGrowthMethod · 0.80
PeakHeapGrowthMethod · 0.80
CompileToProgMethod · 0.80
IsOnePassMethod · 0.80
CanBitStateMethod · 0.80
SearchOnePassMethod · 0.80
ResetMethod · 0.45
DecrefMethod · 0.45

Tested by

no test coverage detected