re2 1.10.2 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +3 -1
- package/.travis.yml +1 -1
- package/README.md +9 -8
- package/lib/addon.cc +4 -6
- package/lib/exec.cc +8 -0
- package/lib/wrapped_re2.h +1 -1
- package/package.json +5 -3
- package/re2.d.ts +5 -1
- package/tests/test_exec.js +1 -0
- package/vendor/re2/bitstate.cc +5 -1
- package/vendor/re2/compile.cc +1 -1
- package/vendor/re2/dfa.cc +8 -11
- package/vendor/re2/nfa.cc +33 -16
- package/vendor/re2/onepass.cc +4 -4
- package/vendor/re2/parse.cc +32 -32
- package/vendor/{util → re2}/pod_array.h +3 -3
- package/vendor/re2/prefilter_tree.h +1 -1
- package/vendor/re2/prog.h +3 -3
- package/vendor/re2/re2.cc +3 -3
- package/vendor/re2/set.cc +2 -2
- package/vendor/re2/simplify.cc +1 -1
- package/vendor/{util → re2}/sparse_array.h +4 -4
- package/vendor/{util → re2}/sparse_set.h +4 -4
- package/vendor/re2/testing/backtrack.cc +4 -0
- package/vendor/re2/testing/dfa_test.cc +12 -10
- package/vendor/re2/testing/dump.cc +4 -10
- package/vendor/re2/testing/exhaustive1_test.cc +2 -7
- package/vendor/re2/testing/exhaustive2_test.cc +0 -1
- package/vendor/re2/testing/exhaustive_tester.cc +11 -8
- package/vendor/re2/testing/random_test.cc +9 -7
- package/vendor/re2/testing/regexp_benchmark.cc +435 -404
- package/vendor/re2/testing/regexp_generator.cc +1 -1
- package/vendor/re2/testing/tester.cc +19 -14
- package/vendor/re2/walker-inl.h +1 -1
- package/vendor/util/benchmark.cc +83 -113
- package/vendor/util/benchmark.h +138 -25
- package/vendor/util/flags.h +8 -11
- package/vendor/util/malloc_counter.h +19 -0
- package/vendor/util/pcre.cc +7 -31
- package/vendor/util/test.cc +4 -1
- package/vendor/util/test.h +4 -12
- package/vendor/util/util.h +8 -0
|
@@ -8,16 +8,19 @@
|
|
|
8
8
|
#include <stdio.h>
|
|
9
9
|
#include <stdlib.h>
|
|
10
10
|
#include <string>
|
|
11
|
+
#include <thread>
|
|
11
12
|
#include <utility>
|
|
12
13
|
|
|
14
|
+
#include "util/benchmark.h"
|
|
13
15
|
#include "util/test.h"
|
|
16
|
+
#include "util/flags.h"
|
|
14
17
|
#include "util/logging.h"
|
|
18
|
+
#include "util/malloc_counter.h"
|
|
15
19
|
#include "util/strutil.h"
|
|
16
20
|
#include "re2/prog.h"
|
|
17
21
|
#include "re2/re2.h"
|
|
18
22
|
#include "re2/regexp.h"
|
|
19
23
|
#include "util/pcre.h"
|
|
20
|
-
#include "util/benchmark.h"
|
|
21
24
|
|
|
22
25
|
namespace re2 {
|
|
23
26
|
void Test();
|
|
@@ -56,19 +59,22 @@ void MemoryUsage() {
|
|
|
56
59
|
CHECK(re);
|
|
57
60
|
// Can't pass mc.HeapGrowth() and mc.PeakHeapGrowth() to LOG(INFO) directly,
|
|
58
61
|
// because LOG(INFO) might do a big allocation before they get evaluated.
|
|
59
|
-
fprintf(stderr, "Regexp: %7lld bytes (peak=%lld)\n",
|
|
62
|
+
fprintf(stderr, "Regexp: %7lld bytes (peak=%lld)\n",
|
|
63
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
60
64
|
mc.Reset();
|
|
61
65
|
|
|
62
66
|
Prog* prog = re->CompileToProg(0);
|
|
63
67
|
CHECK(prog);
|
|
64
68
|
CHECK(prog->IsOnePass());
|
|
65
69
|
CHECK(prog->CanBitState());
|
|
66
|
-
fprintf(stderr, "Prog: %7lld bytes (peak=%lld)\n",
|
|
70
|
+
fprintf(stderr, "Prog: %7lld bytes (peak=%lld)\n",
|
|
71
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
67
72
|
mc.Reset();
|
|
68
73
|
|
|
69
74
|
StringPiece sp[4];
|
|
70
75
|
CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4));
|
|
71
|
-
fprintf(stderr, "Search: %7lld bytes (peak=%lld)\n",
|
|
76
|
+
fprintf(stderr, "Search: %7lld bytes (peak=%lld)\n",
|
|
77
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
72
78
|
delete prog;
|
|
73
79
|
re->Decref();
|
|
74
80
|
}
|
|
@@ -77,18 +83,22 @@ void MemoryUsage() {
|
|
|
77
83
|
MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
|
|
78
84
|
|
|
79
85
|
PCRE re(regexp, PCRE::UTF8);
|
|
80
|
-
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
|
|
86
|
+
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
|
|
87
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
81
88
|
PCRE::FullMatch(text, re);
|
|
82
|
-
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
|
|
89
|
+
fprintf(stderr, "RE: %7lld bytes (peak=%lld)\n",
|
|
90
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
{
|
|
86
94
|
MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
|
|
87
95
|
|
|
88
96
|
PCRE* re = new PCRE(regexp, PCRE::UTF8);
|
|
89
|
-
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
|
|
97
|
+
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
|
|
98
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
90
99
|
PCRE::FullMatch(text, *re);
|
|
91
|
-
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
|
|
100
|
+
fprintf(stderr, "PCRE*: %7lld bytes (peak=%lld)\n",
|
|
101
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
92
102
|
delete re;
|
|
93
103
|
}
|
|
94
104
|
|
|
@@ -96,42 +106,43 @@ void MemoryUsage() {
|
|
|
96
106
|
MallocCounter mc(MallocCounter::THIS_THREAD_ONLY);
|
|
97
107
|
|
|
98
108
|
RE2 re(regexp);
|
|
99
|
-
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
|
|
109
|
+
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
|
|
110
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
100
111
|
RE2::FullMatch(text, re);
|
|
101
|
-
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
|
|
112
|
+
fprintf(stderr, "RE2: %7lld bytes (peak=%lld)\n",
|
|
113
|
+
mc.HeapGrowth(), mc.PeakHeapGrowth());
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
fprintf(stderr, "sizeof: PCRE=%zd RE2=%zd Prog=%zd Inst=%zd\n",
|
|
105
117
|
sizeof(PCRE), sizeof(RE2), sizeof(Prog), sizeof(Prog::Inst));
|
|
106
118
|
}
|
|
107
119
|
|
|
120
|
+
int NumCPUs() {
|
|
121
|
+
return static_cast<int>(std::thread::hardware_concurrency());
|
|
122
|
+
}
|
|
123
|
+
|
|
108
124
|
// Regular expression implementation wrappers.
|
|
109
125
|
// Defined at bottom of file, but they are repetitive
|
|
110
126
|
// and not interesting.
|
|
111
127
|
|
|
112
|
-
typedef void SearchImpl(
|
|
113
|
-
|
|
128
|
+
typedef void SearchImpl(benchmark::State& state, const char* regexp,
|
|
129
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
130
|
+
bool expect_match);
|
|
114
131
|
|
|
115
|
-
SearchImpl SearchDFA, SearchNFA, SearchOnePass, SearchBitState,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
SearchCachedPCRE, SearchCachedRE2;
|
|
132
|
+
SearchImpl SearchDFA, SearchNFA, SearchOnePass, SearchBitState, SearchPCRE,
|
|
133
|
+
SearchRE2, SearchCachedDFA, SearchCachedNFA, SearchCachedOnePass,
|
|
134
|
+
SearchCachedBitState, SearchCachedPCRE, SearchCachedRE2;
|
|
119
135
|
|
|
120
|
-
typedef void ParseImpl(
|
|
136
|
+
typedef void ParseImpl(benchmark::State& state, const char* regexp,
|
|
137
|
+
const StringPiece& text);
|
|
121
138
|
|
|
122
|
-
ParseImpl Parse1NFA, Parse1OnePass, Parse1BitState,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
Parse1CachedNFA, Parse1CachedOnePass, Parse1CachedBitState,
|
|
126
|
-
Parse1CachedPCRE, Parse1CachedRE2,
|
|
127
|
-
Parse1CachedBacktrack;
|
|
139
|
+
ParseImpl Parse1NFA, Parse1OnePass, Parse1BitState, Parse1PCRE, Parse1RE2,
|
|
140
|
+
Parse1Backtrack, Parse1CachedNFA, Parse1CachedOnePass, Parse1CachedBitState,
|
|
141
|
+
Parse1CachedPCRE, Parse1CachedRE2, Parse1CachedBacktrack;
|
|
128
142
|
|
|
129
|
-
ParseImpl Parse3NFA, Parse3OnePass, Parse3BitState,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Parse3CachedNFA, Parse3CachedOnePass, Parse3CachedBitState,
|
|
133
|
-
Parse3CachedPCRE, Parse3CachedRE2,
|
|
134
|
-
Parse3CachedBacktrack;
|
|
143
|
+
ParseImpl Parse3NFA, Parse3OnePass, Parse3BitState, Parse3PCRE, Parse3RE2,
|
|
144
|
+
Parse3Backtrack, Parse3CachedNFA, Parse3CachedOnePass, Parse3CachedBitState,
|
|
145
|
+
Parse3CachedPCRE, Parse3CachedRE2, Parse3CachedBacktrack;
|
|
135
146
|
|
|
136
147
|
ParseImpl SearchParse2CachedPCRE, SearchParse2CachedRE2;
|
|
137
148
|
|
|
@@ -141,10 +152,10 @@ ParseImpl SearchParse1CachedPCRE, SearchParse1CachedRE2;
|
|
|
141
152
|
|
|
142
153
|
// Generate random text that won't contain the search string,
|
|
143
154
|
// to test worst-case search behavior.
|
|
144
|
-
void MakeText(std::string* text,
|
|
155
|
+
void MakeText(std::string* text, int64_t nbytes) {
|
|
145
156
|
srand(1);
|
|
146
157
|
text->resize(nbytes);
|
|
147
|
-
for (
|
|
158
|
+
for (int64_t i = 0; i < nbytes; i++) {
|
|
148
159
|
// Generate a one-byte rune that isn't a control character (e.g. '\n').
|
|
149
160
|
// Clipping to 0x20 introduces some bias, but we don't need uniformity.
|
|
150
161
|
int byte = rand() & 0x7F;
|
|
@@ -156,14 +167,11 @@ void MakeText(std::string* text, int nbytes) {
|
|
|
156
167
|
|
|
157
168
|
// Makes text of size nbytes, then calls run to search
|
|
158
169
|
// the text for regexp iters times.
|
|
159
|
-
void Search(
|
|
160
|
-
StopBenchmarkTiming();
|
|
170
|
+
void Search(benchmark::State& state, const char* regexp, SearchImpl* search) {
|
|
161
171
|
std::string s;
|
|
162
|
-
MakeText(&s,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
search(iters, regexp, s, Prog::kUnanchored, false);
|
|
166
|
-
SetBenchmarkBytesProcessed(static_cast<int64_t>(iters)*nbytes);
|
|
172
|
+
MakeText(&s, state.range(0));
|
|
173
|
+
search(state, regexp, s, Prog::kUnanchored, false);
|
|
174
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
// These two are easy because they start with an A,
|
|
@@ -189,10 +197,10 @@ void Search(int iters, int nbytes, const char* regexp, SearchImpl* search) {
|
|
|
189
197
|
#define PARENS "([ -~])*(A)(B)(C)(D)(E)(F)(G)(H)(I)(J)(K)(L)(M)" \
|
|
190
198
|
"(N)(O)(P)(Q)(R)(S)(T)(U)(V)(W)(X)(Y)(Z)$"
|
|
191
199
|
|
|
192
|
-
void Search_Easy0_CachedDFA(
|
|
193
|
-
void Search_Easy0_CachedNFA(
|
|
194
|
-
void Search_Easy0_CachedPCRE(
|
|
195
|
-
void Search_Easy0_CachedRE2(
|
|
200
|
+
void Search_Easy0_CachedDFA(benchmark::State& state) { Search(state, EASY0, SearchCachedDFA); }
|
|
201
|
+
void Search_Easy0_CachedNFA(benchmark::State& state) { Search(state, EASY0, SearchCachedNFA); }
|
|
202
|
+
void Search_Easy0_CachedPCRE(benchmark::State& state) { Search(state, EASY0, SearchCachedPCRE); }
|
|
203
|
+
void Search_Easy0_CachedRE2(benchmark::State& state) { Search(state, EASY0, SearchCachedRE2); }
|
|
196
204
|
|
|
197
205
|
BENCHMARK_RANGE(Search_Easy0_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
198
206
|
BENCHMARK_RANGE(Search_Easy0_CachedNFA, 8, 256<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -201,10 +209,10 @@ BENCHMARK_RANGE(Search_Easy0_CachedPCRE, 8, 16<<20)->ThreadRange(1, NumCPUs()
|
|
|
201
209
|
#endif
|
|
202
210
|
BENCHMARK_RANGE(Search_Easy0_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
203
211
|
|
|
204
|
-
void Search_Easy1_CachedDFA(
|
|
205
|
-
void Search_Easy1_CachedNFA(
|
|
206
|
-
void Search_Easy1_CachedPCRE(
|
|
207
|
-
void Search_Easy1_CachedRE2(
|
|
212
|
+
void Search_Easy1_CachedDFA(benchmark::State& state) { Search(state, EASY1, SearchCachedDFA); }
|
|
213
|
+
void Search_Easy1_CachedNFA(benchmark::State& state) { Search(state, EASY1, SearchCachedNFA); }
|
|
214
|
+
void Search_Easy1_CachedPCRE(benchmark::State& state) { Search(state, EASY1, SearchCachedPCRE); }
|
|
215
|
+
void Search_Easy1_CachedRE2(benchmark::State& state) { Search(state, EASY1, SearchCachedRE2); }
|
|
208
216
|
|
|
209
217
|
BENCHMARK_RANGE(Search_Easy1_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
210
218
|
BENCHMARK_RANGE(Search_Easy1_CachedNFA, 8, 256<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -213,10 +221,10 @@ BENCHMARK_RANGE(Search_Easy1_CachedPCRE, 8, 16<<20)->ThreadRange(1, NumCPUs()
|
|
|
213
221
|
#endif
|
|
214
222
|
BENCHMARK_RANGE(Search_Easy1_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
215
223
|
|
|
216
|
-
void Search_Medium_CachedDFA(
|
|
217
|
-
void Search_Medium_CachedNFA(
|
|
218
|
-
void Search_Medium_CachedPCRE(
|
|
219
|
-
void Search_Medium_CachedRE2(
|
|
224
|
+
void Search_Medium_CachedDFA(benchmark::State& state) { Search(state, MEDIUM, SearchCachedDFA); }
|
|
225
|
+
void Search_Medium_CachedNFA(benchmark::State& state) { Search(state, MEDIUM, SearchCachedNFA); }
|
|
226
|
+
void Search_Medium_CachedPCRE(benchmark::State& state) { Search(state, MEDIUM, SearchCachedPCRE); }
|
|
227
|
+
void Search_Medium_CachedRE2(benchmark::State& state) { Search(state, MEDIUM, SearchCachedRE2); }
|
|
220
228
|
|
|
221
229
|
BENCHMARK_RANGE(Search_Medium_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
222
230
|
BENCHMARK_RANGE(Search_Medium_CachedNFA, 8, 256<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -225,10 +233,10 @@ BENCHMARK_RANGE(Search_Medium_CachedPCRE, 8, 256<<10)->ThreadRange(1, NumCPUs
|
|
|
225
233
|
#endif
|
|
226
234
|
BENCHMARK_RANGE(Search_Medium_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
227
235
|
|
|
228
|
-
void Search_Hard_CachedDFA(
|
|
229
|
-
void Search_Hard_CachedNFA(
|
|
230
|
-
void Search_Hard_CachedPCRE(
|
|
231
|
-
void Search_Hard_CachedRE2(
|
|
236
|
+
void Search_Hard_CachedDFA(benchmark::State& state) { Search(state, HARD, SearchCachedDFA); }
|
|
237
|
+
void Search_Hard_CachedNFA(benchmark::State& state) { Search(state, HARD, SearchCachedNFA); }
|
|
238
|
+
void Search_Hard_CachedPCRE(benchmark::State& state) { Search(state, HARD, SearchCachedPCRE); }
|
|
239
|
+
void Search_Hard_CachedRE2(benchmark::State& state) { Search(state, HARD, SearchCachedRE2); }
|
|
232
240
|
|
|
233
241
|
BENCHMARK_RANGE(Search_Hard_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
234
242
|
BENCHMARK_RANGE(Search_Hard_CachedNFA, 8, 256<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -237,10 +245,10 @@ BENCHMARK_RANGE(Search_Hard_CachedPCRE, 8, 4<<10)->ThreadRange(1, NumCPUs());
|
|
|
237
245
|
#endif
|
|
238
246
|
BENCHMARK_RANGE(Search_Hard_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
239
247
|
|
|
240
|
-
void Search_Fanout_CachedDFA(
|
|
241
|
-
void Search_Fanout_CachedNFA(
|
|
242
|
-
void Search_Fanout_CachedPCRE(
|
|
243
|
-
void Search_Fanout_CachedRE2(
|
|
248
|
+
void Search_Fanout_CachedDFA(benchmark::State& state) { Search(state, FANOUT, SearchCachedDFA); }
|
|
249
|
+
void Search_Fanout_CachedNFA(benchmark::State& state) { Search(state, FANOUT, SearchCachedNFA); }
|
|
250
|
+
void Search_Fanout_CachedPCRE(benchmark::State& state) { Search(state, FANOUT, SearchCachedPCRE); }
|
|
251
|
+
void Search_Fanout_CachedRE2(benchmark::State& state) { Search(state, FANOUT, SearchCachedRE2); }
|
|
244
252
|
|
|
245
253
|
BENCHMARK_RANGE(Search_Fanout_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
246
254
|
BENCHMARK_RANGE(Search_Fanout_CachedNFA, 8, 256<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -249,10 +257,10 @@ BENCHMARK_RANGE(Search_Fanout_CachedPCRE, 8, 4<<10)->ThreadRange(1, NumCPUs()
|
|
|
249
257
|
#endif
|
|
250
258
|
BENCHMARK_RANGE(Search_Fanout_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
251
259
|
|
|
252
|
-
void Search_Parens_CachedDFA(
|
|
253
|
-
void Search_Parens_CachedNFA(
|
|
254
|
-
void Search_Parens_CachedPCRE(
|
|
255
|
-
void Search_Parens_CachedRE2(
|
|
260
|
+
void Search_Parens_CachedDFA(benchmark::State& state) { Search(state, PARENS, SearchCachedDFA); }
|
|
261
|
+
void Search_Parens_CachedNFA(benchmark::State& state) { Search(state, PARENS, SearchCachedNFA); }
|
|
262
|
+
void Search_Parens_CachedPCRE(benchmark::State& state) { Search(state, PARENS, SearchCachedPCRE); }
|
|
263
|
+
void Search_Parens_CachedRE2(benchmark::State& state) { Search(state, PARENS, SearchCachedRE2); }
|
|
256
264
|
|
|
257
265
|
BENCHMARK_RANGE(Search_Parens_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
258
266
|
BENCHMARK_RANGE(Search_Parens_CachedNFA, 8, 256<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -261,24 +269,21 @@ BENCHMARK_RANGE(Search_Parens_CachedPCRE, 8, 8)->ThreadRange(1, NumCPUs());
|
|
|
261
269
|
#endif
|
|
262
270
|
BENCHMARK_RANGE(Search_Parens_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
263
271
|
|
|
264
|
-
void SearchBigFixed(
|
|
265
|
-
StopBenchmarkTiming();
|
|
272
|
+
void SearchBigFixed(benchmark::State& state, SearchImpl* search) {
|
|
266
273
|
std::string s;
|
|
267
|
-
s.append(
|
|
274
|
+
s.append(state.range(0)/2, 'x');
|
|
268
275
|
std::string regexp = "^" + s + ".*$";
|
|
269
276
|
std::string t;
|
|
270
|
-
MakeText(&t,
|
|
277
|
+
MakeText(&t, state.range(0)/2);
|
|
271
278
|
s += t;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
search(iters, regexp.c_str(), s, Prog::kUnanchored, true);
|
|
275
|
-
SetBenchmarkBytesProcessed(static_cast<int64_t>(iters)*nbytes);
|
|
279
|
+
search(state, regexp.c_str(), s, Prog::kUnanchored, true);
|
|
280
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
276
281
|
}
|
|
277
282
|
|
|
278
|
-
void Search_BigFixed_CachedDFA(
|
|
279
|
-
void Search_BigFixed_CachedNFA(
|
|
280
|
-
void Search_BigFixed_CachedPCRE(
|
|
281
|
-
void Search_BigFixed_CachedRE2(
|
|
283
|
+
void Search_BigFixed_CachedDFA(benchmark::State& state) { SearchBigFixed(state, SearchCachedDFA); }
|
|
284
|
+
void Search_BigFixed_CachedNFA(benchmark::State& state) { SearchBigFixed(state, SearchCachedNFA); }
|
|
285
|
+
void Search_BigFixed_CachedPCRE(benchmark::State& state) { SearchBigFixed(state, SearchCachedPCRE); }
|
|
286
|
+
void Search_BigFixed_CachedRE2(benchmark::State& state) { SearchBigFixed(state, SearchCachedRE2); }
|
|
282
287
|
|
|
283
288
|
BENCHMARK_RANGE(Search_BigFixed_CachedDFA, 8, 1<<20)->ThreadRange(1, NumCPUs());
|
|
284
289
|
BENCHMARK_RANGE(Search_BigFixed_CachedNFA, 8, 32<<10)->ThreadRange(1, NumCPUs());
|
|
@@ -289,43 +294,39 @@ BENCHMARK_RANGE(Search_BigFixed_CachedRE2, 8, 1<<20)->ThreadRange(1, NumCPUs
|
|
|
289
294
|
|
|
290
295
|
// Benchmark: FindAndConsume
|
|
291
296
|
|
|
292
|
-
void FindAndConsume(
|
|
293
|
-
StopBenchmarkTiming();
|
|
297
|
+
void FindAndConsume(benchmark::State& state) {
|
|
294
298
|
std::string s;
|
|
295
|
-
MakeText(&s,
|
|
299
|
+
MakeText(&s, state.range(0));
|
|
296
300
|
s.append("Hello World");
|
|
297
|
-
StartBenchmarkTiming();
|
|
298
301
|
RE2 re("((Hello World))");
|
|
299
|
-
for (
|
|
302
|
+
for (auto _ : state) {
|
|
300
303
|
StringPiece t = s;
|
|
301
304
|
StringPiece u;
|
|
302
305
|
CHECK(RE2::FindAndConsume(&t, re, &u));
|
|
303
306
|
CHECK_EQ(u, "Hello World");
|
|
304
307
|
}
|
|
305
|
-
|
|
308
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
306
309
|
}
|
|
307
310
|
|
|
308
311
|
BENCHMARK_RANGE(FindAndConsume, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
309
312
|
|
|
310
313
|
// Benchmark: successful anchored search.
|
|
311
314
|
|
|
312
|
-
void SearchSuccess(
|
|
313
|
-
|
|
315
|
+
void SearchSuccess(benchmark::State& state, const char* regexp,
|
|
316
|
+
SearchImpl* search) {
|
|
314
317
|
std::string s;
|
|
315
|
-
MakeText(&s,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
search(iters, regexp, s, Prog::kAnchored, true);
|
|
319
|
-
SetBenchmarkBytesProcessed(static_cast<int64_t>(iters)*nbytes);
|
|
318
|
+
MakeText(&s, state.range(0));
|
|
319
|
+
search(state, regexp, s, Prog::kAnchored, true);
|
|
320
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
// Unambiguous search (RE2 can use OnePass).
|
|
323
324
|
|
|
324
|
-
void Search_Success_DFA(
|
|
325
|
-
void Search_Success_NFA(
|
|
326
|
-
void Search_Success_PCRE(
|
|
327
|
-
void Search_Success_RE2(
|
|
328
|
-
void Search_Success_OnePass(
|
|
325
|
+
void Search_Success_DFA(benchmark::State& state) { SearchSuccess(state, ".*$", SearchDFA); }
|
|
326
|
+
void Search_Success_NFA(benchmark::State& state) { SearchSuccess(state, ".*$", SearchNFA); }
|
|
327
|
+
void Search_Success_PCRE(benchmark::State& state) { SearchSuccess(state, ".*$", SearchPCRE); }
|
|
328
|
+
void Search_Success_RE2(benchmark::State& state) { SearchSuccess(state, ".*$", SearchRE2); }
|
|
329
|
+
void Search_Success_OnePass(benchmark::State& state) { SearchSuccess(state, ".*$", SearchOnePass); }
|
|
329
330
|
|
|
330
331
|
BENCHMARK_RANGE(Search_Success_DFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
331
332
|
BENCHMARK_RANGE(Search_Success_NFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
@@ -335,11 +336,11 @@ BENCHMARK_RANGE(Search_Success_PCRE, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
|
335
336
|
BENCHMARK_RANGE(Search_Success_RE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
336
337
|
BENCHMARK_RANGE(Search_Success_OnePass, 8, 2<<20)->ThreadRange(1, NumCPUs());
|
|
337
338
|
|
|
338
|
-
void Search_Success_CachedDFA(
|
|
339
|
-
void Search_Success_CachedNFA(
|
|
340
|
-
void Search_Success_CachedPCRE(
|
|
341
|
-
void Search_Success_CachedRE2(
|
|
342
|
-
void Search_Success_CachedOnePass(
|
|
339
|
+
void Search_Success_CachedDFA(benchmark::State& state) { SearchSuccess(state, ".*$", SearchCachedDFA); }
|
|
340
|
+
void Search_Success_CachedNFA(benchmark::State& state) { SearchSuccess(state, ".*$", SearchCachedNFA); }
|
|
341
|
+
void Search_Success_CachedPCRE(benchmark::State& state) { SearchSuccess(state, ".*$", SearchCachedPCRE); }
|
|
342
|
+
void Search_Success_CachedRE2(benchmark::State& state) { SearchSuccess(state, ".*$", SearchCachedRE2); }
|
|
343
|
+
void Search_Success_CachedOnePass(benchmark::State& state) { SearchSuccess(state, ".*$", SearchCachedOnePass); }
|
|
343
344
|
|
|
344
345
|
BENCHMARK_RANGE(Search_Success_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
345
346
|
BENCHMARK_RANGE(Search_Success_CachedNFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
@@ -352,11 +353,11 @@ BENCHMARK_RANGE(Search_Success_CachedOnePass, 8, 2<<20)->ThreadRange(1, NumCPUs(
|
|
|
352
353
|
// Ambiguous search (RE2 cannot use OnePass).
|
|
353
354
|
// Used to be ".*.$", but that is coalesced to ".+$" these days.
|
|
354
355
|
|
|
355
|
-
void Search_Success1_DFA(
|
|
356
|
-
void Search_Success1_NFA(
|
|
357
|
-
void Search_Success1_PCRE(
|
|
358
|
-
void Search_Success1_RE2(
|
|
359
|
-
void Search_Success1_BitState(
|
|
356
|
+
void Search_Success1_DFA(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchDFA); }
|
|
357
|
+
void Search_Success1_NFA(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchNFA); }
|
|
358
|
+
void Search_Success1_PCRE(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchPCRE); }
|
|
359
|
+
void Search_Success1_RE2(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchRE2); }
|
|
360
|
+
void Search_Success1_BitState(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchBitState); }
|
|
360
361
|
|
|
361
362
|
BENCHMARK_RANGE(Search_Success1_DFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
362
363
|
BENCHMARK_RANGE(Search_Success1_NFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
@@ -366,11 +367,11 @@ BENCHMARK_RANGE(Search_Success1_PCRE, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
|
366
367
|
BENCHMARK_RANGE(Search_Success1_RE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
367
368
|
BENCHMARK_RANGE(Search_Success1_BitState, 8, 2<<20)->ThreadRange(1, NumCPUs());
|
|
368
369
|
|
|
369
|
-
void Search_Success1_CachedDFA(
|
|
370
|
-
void Search_Success1_CachedNFA(
|
|
371
|
-
void Search_Success1_CachedPCRE(
|
|
372
|
-
void Search_Success1_CachedRE2(
|
|
373
|
-
void Search_Success1_CachedBitState(
|
|
370
|
+
void Search_Success1_CachedDFA(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchCachedDFA); }
|
|
371
|
+
void Search_Success1_CachedNFA(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchCachedNFA); }
|
|
372
|
+
void Search_Success1_CachedPCRE(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchCachedPCRE); }
|
|
373
|
+
void Search_Success1_CachedRE2(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchCachedRE2); }
|
|
374
|
+
void Search_Success1_CachedBitState(benchmark::State& state) { SearchSuccess(state, ".*\\C$", SearchCachedBitState); }
|
|
374
375
|
|
|
375
376
|
BENCHMARK_RANGE(Search_Success1_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
376
377
|
BENCHMARK_RANGE(Search_Success1_CachedNFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
@@ -383,22 +384,19 @@ BENCHMARK_RANGE(Search_Success1_CachedBitState, 8, 2<<20)->ThreadRange(1, NumCPU
|
|
|
383
384
|
// Benchmark: AltMatch optimisation (just to verify that it works)
|
|
384
385
|
// Note that OnePass doesn't implement it!
|
|
385
386
|
|
|
386
|
-
void SearchAltMatch(
|
|
387
|
-
StopBenchmarkTiming();
|
|
387
|
+
void SearchAltMatch(benchmark::State& state, SearchImpl* search) {
|
|
388
388
|
std::string s;
|
|
389
|
-
MakeText(&s,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
search(iters, "\\C*", s, Prog::kAnchored, true);
|
|
393
|
-
SetBenchmarkBytesProcessed(static_cast<int64_t>(iters)*nbytes);
|
|
389
|
+
MakeText(&s, state.range(0));
|
|
390
|
+
search(state, "\\C*", s, Prog::kAnchored, true);
|
|
391
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
394
392
|
}
|
|
395
393
|
|
|
396
|
-
void Search_AltMatch_DFA(
|
|
397
|
-
void Search_AltMatch_NFA(
|
|
398
|
-
void Search_AltMatch_OnePass(
|
|
399
|
-
void Search_AltMatch_BitState(
|
|
400
|
-
void Search_AltMatch_PCRE(
|
|
401
|
-
void Search_AltMatch_RE2(
|
|
394
|
+
void Search_AltMatch_DFA(benchmark::State& state) { SearchAltMatch(state, SearchDFA); }
|
|
395
|
+
void Search_AltMatch_NFA(benchmark::State& state) { SearchAltMatch(state, SearchNFA); }
|
|
396
|
+
void Search_AltMatch_OnePass(benchmark::State& state) { SearchAltMatch(state, SearchOnePass); }
|
|
397
|
+
void Search_AltMatch_BitState(benchmark::State& state) { SearchAltMatch(state, SearchBitState); }
|
|
398
|
+
void Search_AltMatch_PCRE(benchmark::State& state) { SearchAltMatch(state, SearchPCRE); }
|
|
399
|
+
void Search_AltMatch_RE2(benchmark::State& state) { SearchAltMatch(state, SearchRE2); }
|
|
402
400
|
|
|
403
401
|
BENCHMARK_RANGE(Search_AltMatch_DFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
404
402
|
BENCHMARK_RANGE(Search_AltMatch_NFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
@@ -409,12 +407,12 @@ BENCHMARK_RANGE(Search_AltMatch_PCRE, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
|
409
407
|
#endif
|
|
410
408
|
BENCHMARK_RANGE(Search_AltMatch_RE2, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
411
409
|
|
|
412
|
-
void Search_AltMatch_CachedDFA(
|
|
413
|
-
void Search_AltMatch_CachedNFA(
|
|
414
|
-
void Search_AltMatch_CachedOnePass(
|
|
415
|
-
void Search_AltMatch_CachedBitState(
|
|
416
|
-
void Search_AltMatch_CachedPCRE(
|
|
417
|
-
void Search_AltMatch_CachedRE2(
|
|
410
|
+
void Search_AltMatch_CachedDFA(benchmark::State& state) { SearchAltMatch(state, SearchCachedDFA); }
|
|
411
|
+
void Search_AltMatch_CachedNFA(benchmark::State& state) { SearchAltMatch(state, SearchCachedNFA); }
|
|
412
|
+
void Search_AltMatch_CachedOnePass(benchmark::State& state) { SearchAltMatch(state, SearchCachedOnePass); }
|
|
413
|
+
void Search_AltMatch_CachedBitState(benchmark::State& state) { SearchAltMatch(state, SearchCachedBitState); }
|
|
414
|
+
void Search_AltMatch_CachedPCRE(benchmark::State& state) { SearchAltMatch(state, SearchCachedPCRE); }
|
|
415
|
+
void Search_AltMatch_CachedRE2(benchmark::State& state) { SearchAltMatch(state, SearchCachedRE2); }
|
|
418
416
|
|
|
419
417
|
BENCHMARK_RANGE(Search_AltMatch_CachedDFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
420
418
|
BENCHMARK_RANGE(Search_AltMatch_CachedNFA, 8, 16<<20)->ThreadRange(1, NumCPUs());
|
|
@@ -427,19 +425,18 @@ BENCHMARK_RANGE(Search_AltMatch_CachedRE2, 8, 16<<20)->ThreadRange(1, NumCP
|
|
|
427
425
|
|
|
428
426
|
// Benchmark: use regexp to find phone number.
|
|
429
427
|
|
|
430
|
-
void SearchDigits(
|
|
428
|
+
void SearchDigits(benchmark::State& state, SearchImpl* search) {
|
|
431
429
|
StringPiece s("650-253-0001");
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
SetBenchmarkItemsProcessed(iters);
|
|
430
|
+
search(state, "([0-9]+)-([0-9]+)-([0-9]+)", s, Prog::kAnchored, true);
|
|
431
|
+
state.SetItemsProcessed(state.iterations());
|
|
435
432
|
}
|
|
436
433
|
|
|
437
|
-
void Search_Digits_DFA(
|
|
438
|
-
void Search_Digits_NFA(
|
|
439
|
-
void Search_Digits_OnePass(
|
|
440
|
-
void Search_Digits_PCRE(
|
|
441
|
-
void Search_Digits_RE2(
|
|
442
|
-
void Search_Digits_BitState(
|
|
434
|
+
void Search_Digits_DFA(benchmark::State& state) { SearchDigits(state, SearchDFA); }
|
|
435
|
+
void Search_Digits_NFA(benchmark::State& state) { SearchDigits(state, SearchNFA); }
|
|
436
|
+
void Search_Digits_OnePass(benchmark::State& state) { SearchDigits(state, SearchOnePass); }
|
|
437
|
+
void Search_Digits_PCRE(benchmark::State& state) { SearchDigits(state, SearchPCRE); }
|
|
438
|
+
void Search_Digits_RE2(benchmark::State& state) { SearchDigits(state, SearchRE2); }
|
|
439
|
+
void Search_Digits_BitState(benchmark::State& state) { SearchDigits(state, SearchBitState); }
|
|
443
440
|
|
|
444
441
|
BENCHMARK(Search_Digits_DFA)->ThreadRange(1, NumCPUs());
|
|
445
442
|
BENCHMARK(Search_Digits_NFA)->ThreadRange(1, NumCPUs());
|
|
@@ -452,19 +449,19 @@ BENCHMARK(Search_Digits_BitState)->ThreadRange(1, NumCPUs());
|
|
|
452
449
|
|
|
453
450
|
// Benchmark: use regexp to parse digit fields in phone number.
|
|
454
451
|
|
|
455
|
-
void Parse3Digits(
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
parse3(
|
|
459
|
-
|
|
452
|
+
void Parse3Digits(benchmark::State& state,
|
|
453
|
+
void (*parse3)(benchmark::State&, const char*,
|
|
454
|
+
const StringPiece&)) {
|
|
455
|
+
parse3(state, "([0-9]+)-([0-9]+)-([0-9]+)", "650-253-0001");
|
|
456
|
+
state.SetItemsProcessed(state.iterations());
|
|
460
457
|
}
|
|
461
458
|
|
|
462
|
-
void Parse_Digits_NFA(
|
|
463
|
-
void Parse_Digits_OnePass(
|
|
464
|
-
void Parse_Digits_PCRE(
|
|
465
|
-
void Parse_Digits_RE2(
|
|
466
|
-
void Parse_Digits_Backtrack(
|
|
467
|
-
void Parse_Digits_BitState(
|
|
459
|
+
void Parse_Digits_NFA(benchmark::State& state) { Parse3Digits(state, Parse3NFA); }
|
|
460
|
+
void Parse_Digits_OnePass(benchmark::State& state) { Parse3Digits(state, Parse3OnePass); }
|
|
461
|
+
void Parse_Digits_PCRE(benchmark::State& state) { Parse3Digits(state, Parse3PCRE); }
|
|
462
|
+
void Parse_Digits_RE2(benchmark::State& state) { Parse3Digits(state, Parse3RE2); }
|
|
463
|
+
void Parse_Digits_Backtrack(benchmark::State& state) { Parse3Digits(state, Parse3Backtrack); }
|
|
464
|
+
void Parse_Digits_BitState(benchmark::State& state) { Parse3Digits(state, Parse3BitState); }
|
|
468
465
|
|
|
469
466
|
BENCHMARK(Parse_Digits_NFA)->ThreadRange(1, NumCPUs());
|
|
470
467
|
BENCHMARK(Parse_Digits_OnePass)->ThreadRange(1, NumCPUs());
|
|
@@ -475,12 +472,12 @@ BENCHMARK(Parse_Digits_RE2)->ThreadRange(1, NumCPUs());
|
|
|
475
472
|
BENCHMARK(Parse_Digits_Backtrack)->ThreadRange(1, NumCPUs());
|
|
476
473
|
BENCHMARK(Parse_Digits_BitState)->ThreadRange(1, NumCPUs());
|
|
477
474
|
|
|
478
|
-
void Parse_CachedDigits_NFA(
|
|
479
|
-
void Parse_CachedDigits_OnePass(
|
|
480
|
-
void Parse_CachedDigits_PCRE(
|
|
481
|
-
void Parse_CachedDigits_RE2(
|
|
482
|
-
void Parse_CachedDigits_Backtrack(
|
|
483
|
-
void Parse_CachedDigits_BitState(
|
|
475
|
+
void Parse_CachedDigits_NFA(benchmark::State& state) { Parse3Digits(state, Parse3CachedNFA); }
|
|
476
|
+
void Parse_CachedDigits_OnePass(benchmark::State& state) { Parse3Digits(state, Parse3CachedOnePass); }
|
|
477
|
+
void Parse_CachedDigits_PCRE(benchmark::State& state) { Parse3Digits(state, Parse3CachedPCRE); }
|
|
478
|
+
void Parse_CachedDigits_RE2(benchmark::State& state) { Parse3Digits(state, Parse3CachedRE2); }
|
|
479
|
+
void Parse_CachedDigits_Backtrack(benchmark::State& state) { Parse3Digits(state, Parse3CachedBacktrack); }
|
|
480
|
+
void Parse_CachedDigits_BitState(benchmark::State& state) { Parse3Digits(state, Parse3CachedBitState); }
|
|
484
481
|
|
|
485
482
|
BENCHMARK(Parse_CachedDigits_NFA)->ThreadRange(1, NumCPUs());
|
|
486
483
|
BENCHMARK(Parse_CachedDigits_OnePass)->ThreadRange(1, NumCPUs());
|
|
@@ -491,19 +488,19 @@ BENCHMARK(Parse_CachedDigits_Backtrack)->ThreadRange(1, NumCPUs());
|
|
|
491
488
|
BENCHMARK(Parse_CachedDigits_RE2)->ThreadRange(1, NumCPUs());
|
|
492
489
|
BENCHMARK(Parse_CachedDigits_BitState)->ThreadRange(1, NumCPUs());
|
|
493
490
|
|
|
494
|
-
void Parse3DigitDs(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
parse3(
|
|
498
|
-
|
|
491
|
+
void Parse3DigitDs(benchmark::State& state,
|
|
492
|
+
void (*parse3)(benchmark::State&, const char*,
|
|
493
|
+
const StringPiece&)) {
|
|
494
|
+
parse3(state, "(\\d+)-(\\d+)-(\\d+)", "650-253-0001");
|
|
495
|
+
state.SetItemsProcessed(state.iterations());
|
|
499
496
|
}
|
|
500
497
|
|
|
501
|
-
void Parse_DigitDs_NFA(
|
|
502
|
-
void Parse_DigitDs_OnePass(
|
|
503
|
-
void Parse_DigitDs_PCRE(
|
|
504
|
-
void Parse_DigitDs_RE2(
|
|
505
|
-
void Parse_DigitDs_Backtrack(
|
|
506
|
-
void Parse_DigitDs_BitState(
|
|
498
|
+
void Parse_DigitDs_NFA(benchmark::State& state) { Parse3DigitDs(state, Parse3NFA); }
|
|
499
|
+
void Parse_DigitDs_OnePass(benchmark::State& state) { Parse3DigitDs(state, Parse3OnePass); }
|
|
500
|
+
void Parse_DigitDs_PCRE(benchmark::State& state) { Parse3DigitDs(state, Parse3PCRE); }
|
|
501
|
+
void Parse_DigitDs_RE2(benchmark::State& state) { Parse3DigitDs(state, Parse3RE2); }
|
|
502
|
+
void Parse_DigitDs_Backtrack(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedBacktrack); }
|
|
503
|
+
void Parse_DigitDs_BitState(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedBitState); }
|
|
507
504
|
|
|
508
505
|
BENCHMARK(Parse_DigitDs_NFA)->ThreadRange(1, NumCPUs());
|
|
509
506
|
BENCHMARK(Parse_DigitDs_OnePass)->ThreadRange(1, NumCPUs());
|
|
@@ -514,12 +511,12 @@ BENCHMARK(Parse_DigitDs_RE2)->ThreadRange(1, NumCPUs());
|
|
|
514
511
|
BENCHMARK(Parse_DigitDs_Backtrack)->ThreadRange(1, NumCPUs());
|
|
515
512
|
BENCHMARK(Parse_DigitDs_BitState)->ThreadRange(1, NumCPUs());
|
|
516
513
|
|
|
517
|
-
void Parse_CachedDigitDs_NFA(
|
|
518
|
-
void Parse_CachedDigitDs_OnePass(
|
|
519
|
-
void Parse_CachedDigitDs_PCRE(
|
|
520
|
-
void Parse_CachedDigitDs_RE2(
|
|
521
|
-
void Parse_CachedDigitDs_Backtrack(
|
|
522
|
-
void Parse_CachedDigitDs_BitState(
|
|
514
|
+
void Parse_CachedDigitDs_NFA(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedNFA); }
|
|
515
|
+
void Parse_CachedDigitDs_OnePass(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedOnePass); }
|
|
516
|
+
void Parse_CachedDigitDs_PCRE(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedPCRE); }
|
|
517
|
+
void Parse_CachedDigitDs_RE2(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedRE2); }
|
|
518
|
+
void Parse_CachedDigitDs_Backtrack(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedBacktrack); }
|
|
519
|
+
void Parse_CachedDigitDs_BitState(benchmark::State& state) { Parse3DigitDs(state, Parse3CachedBitState); }
|
|
523
520
|
|
|
524
521
|
BENCHMARK(Parse_CachedDigitDs_NFA)->ThreadRange(1, NumCPUs());
|
|
525
522
|
BENCHMARK(Parse_CachedDigitDs_OnePass)->ThreadRange(1, NumCPUs());
|
|
@@ -532,18 +529,18 @@ BENCHMARK(Parse_CachedDigitDs_BitState)->ThreadRange(1, NumCPUs());
|
|
|
532
529
|
|
|
533
530
|
// Benchmark: splitting off leading number field.
|
|
534
531
|
|
|
535
|
-
void Parse1Split(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
parse1(
|
|
539
|
-
|
|
532
|
+
void Parse1Split(benchmark::State& state,
|
|
533
|
+
void (*parse1)(benchmark::State&, const char*,
|
|
534
|
+
const StringPiece&)) {
|
|
535
|
+
parse1(state, "[0-9]+-(.*)", "650-253-0001");
|
|
536
|
+
state.SetItemsProcessed(state.iterations());
|
|
540
537
|
}
|
|
541
538
|
|
|
542
|
-
void Parse_Split_NFA(
|
|
543
|
-
void Parse_Split_OnePass(
|
|
544
|
-
void Parse_Split_PCRE(
|
|
545
|
-
void Parse_Split_RE2(
|
|
546
|
-
void Parse_Split_BitState(
|
|
539
|
+
void Parse_Split_NFA(benchmark::State& state) { Parse1Split(state, Parse1NFA); }
|
|
540
|
+
void Parse_Split_OnePass(benchmark::State& state) { Parse1Split(state, Parse1OnePass); }
|
|
541
|
+
void Parse_Split_PCRE(benchmark::State& state) { Parse1Split(state, Parse1PCRE); }
|
|
542
|
+
void Parse_Split_RE2(benchmark::State& state) { Parse1Split(state, Parse1RE2); }
|
|
543
|
+
void Parse_Split_BitState(benchmark::State& state) { Parse1Split(state, Parse1BitState); }
|
|
547
544
|
|
|
548
545
|
BENCHMARK(Parse_Split_NFA)->ThreadRange(1, NumCPUs());
|
|
549
546
|
BENCHMARK(Parse_Split_OnePass)->ThreadRange(1, NumCPUs());
|
|
@@ -553,11 +550,11 @@ BENCHMARK(Parse_Split_PCRE)->ThreadRange(1, NumCPUs());
|
|
|
553
550
|
BENCHMARK(Parse_Split_RE2)->ThreadRange(1, NumCPUs());
|
|
554
551
|
BENCHMARK(Parse_Split_BitState)->ThreadRange(1, NumCPUs());
|
|
555
552
|
|
|
556
|
-
void Parse_CachedSplit_NFA(
|
|
557
|
-
void Parse_CachedSplit_OnePass(
|
|
558
|
-
void Parse_CachedSplit_PCRE(
|
|
559
|
-
void Parse_CachedSplit_RE2(
|
|
560
|
-
void Parse_CachedSplit_BitState(
|
|
553
|
+
void Parse_CachedSplit_NFA(benchmark::State& state) { Parse1Split(state, Parse1CachedNFA); }
|
|
554
|
+
void Parse_CachedSplit_OnePass(benchmark::State& state) { Parse1Split(state, Parse1CachedOnePass); }
|
|
555
|
+
void Parse_CachedSplit_PCRE(benchmark::State& state) { Parse1Split(state, Parse1CachedPCRE); }
|
|
556
|
+
void Parse_CachedSplit_RE2(benchmark::State& state) { Parse1Split(state, Parse1CachedRE2); }
|
|
557
|
+
void Parse_CachedSplit_BitState(benchmark::State& state) { Parse1Split(state, Parse1CachedBitState); }
|
|
561
558
|
|
|
562
559
|
BENCHMARK(Parse_CachedSplit_NFA)->ThreadRange(1, NumCPUs());
|
|
563
560
|
BENCHMARK(Parse_CachedSplit_OnePass)->ThreadRange(1, NumCPUs());
|
|
@@ -569,17 +566,17 @@ BENCHMARK(Parse_CachedSplit_BitState)->ThreadRange(1, NumCPUs());
|
|
|
569
566
|
|
|
570
567
|
// Benchmark: splitting off leading number field but harder (ambiguous regexp).
|
|
571
568
|
|
|
572
|
-
void Parse1SplitHard(
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
run(
|
|
576
|
-
|
|
569
|
+
void Parse1SplitHard(benchmark::State& state,
|
|
570
|
+
void (*run)(benchmark::State&, const char*,
|
|
571
|
+
const StringPiece&)) {
|
|
572
|
+
run(state, "[0-9]+.(.*)", "650-253-0001");
|
|
573
|
+
state.SetItemsProcessed(state.iterations());
|
|
577
574
|
}
|
|
578
575
|
|
|
579
|
-
void Parse_SplitHard_NFA(
|
|
580
|
-
void Parse_SplitHard_PCRE(
|
|
581
|
-
void Parse_SplitHard_RE2(
|
|
582
|
-
void Parse_SplitHard_BitState(
|
|
576
|
+
void Parse_SplitHard_NFA(benchmark::State& state) { Parse1SplitHard(state, Parse1NFA); }
|
|
577
|
+
void Parse_SplitHard_PCRE(benchmark::State& state) { Parse1SplitHard(state, Parse1PCRE); }
|
|
578
|
+
void Parse_SplitHard_RE2(benchmark::State& state) { Parse1SplitHard(state, Parse1RE2); }
|
|
579
|
+
void Parse_SplitHard_BitState(benchmark::State& state) { Parse1SplitHard(state, Parse1BitState); }
|
|
583
580
|
|
|
584
581
|
#ifdef USEPCRE
|
|
585
582
|
BENCHMARK(Parse_SplitHard_PCRE)->ThreadRange(1, NumCPUs());
|
|
@@ -588,11 +585,11 @@ BENCHMARK(Parse_SplitHard_RE2)->ThreadRange(1, NumCPUs());
|
|
|
588
585
|
BENCHMARK(Parse_SplitHard_BitState)->ThreadRange(1, NumCPUs());
|
|
589
586
|
BENCHMARK(Parse_SplitHard_NFA)->ThreadRange(1, NumCPUs());
|
|
590
587
|
|
|
591
|
-
void Parse_CachedSplitHard_NFA(
|
|
592
|
-
void Parse_CachedSplitHard_PCRE(
|
|
593
|
-
void Parse_CachedSplitHard_RE2(
|
|
594
|
-
void Parse_CachedSplitHard_BitState(
|
|
595
|
-
void Parse_CachedSplitHard_Backtrack(
|
|
588
|
+
void Parse_CachedSplitHard_NFA(benchmark::State& state) { Parse1SplitHard(state, Parse1CachedNFA); }
|
|
589
|
+
void Parse_CachedSplitHard_PCRE(benchmark::State& state) { Parse1SplitHard(state, Parse1CachedPCRE); }
|
|
590
|
+
void Parse_CachedSplitHard_RE2(benchmark::State& state) { Parse1SplitHard(state, Parse1CachedRE2); }
|
|
591
|
+
void Parse_CachedSplitHard_BitState(benchmark::State& state) { Parse1SplitHard(state, Parse1CachedBitState); }
|
|
592
|
+
void Parse_CachedSplitHard_Backtrack(benchmark::State& state) { Parse1SplitHard(state, Parse1CachedBacktrack); }
|
|
596
593
|
|
|
597
594
|
#ifdef USEPCRE
|
|
598
595
|
BENCHMARK(Parse_CachedSplitHard_PCRE)->ThreadRange(1, NumCPUs());
|
|
@@ -604,18 +601,18 @@ BENCHMARK(Parse_CachedSplitHard_Backtrack)->ThreadRange(1, NumCPUs());
|
|
|
604
601
|
|
|
605
602
|
// Benchmark: Parse1SplitHard, big text, small match.
|
|
606
603
|
|
|
607
|
-
void Parse1SplitBig1(
|
|
608
|
-
|
|
604
|
+
void Parse1SplitBig1(benchmark::State& state,
|
|
605
|
+
void (*run)(benchmark::State&, const char*,
|
|
606
|
+
const StringPiece&)) {
|
|
609
607
|
std::string s;
|
|
610
608
|
s.append(100000, 'x');
|
|
611
609
|
s.append("650-253-0001");
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
SetBenchmarkItemsProcessed(iters);
|
|
610
|
+
run(state, "[0-9]+.(.*)", s);
|
|
611
|
+
state.SetItemsProcessed(state.iterations());
|
|
615
612
|
}
|
|
616
613
|
|
|
617
|
-
void Parse_CachedSplitBig1_PCRE(
|
|
618
|
-
void Parse_CachedSplitBig1_RE2(
|
|
614
|
+
void Parse_CachedSplitBig1_PCRE(benchmark::State& state) { Parse1SplitBig1(state, SearchParse1CachedPCRE); }
|
|
615
|
+
void Parse_CachedSplitBig1_RE2(benchmark::State& state) { Parse1SplitBig1(state, SearchParse1CachedRE2); }
|
|
619
616
|
|
|
620
617
|
#ifdef USEPCRE
|
|
621
618
|
BENCHMARK(Parse_CachedSplitBig1_PCRE)->ThreadRange(1, NumCPUs());
|
|
@@ -624,18 +621,18 @@ BENCHMARK(Parse_CachedSplitBig1_RE2)->ThreadRange(1, NumCPUs());
|
|
|
624
621
|
|
|
625
622
|
// Benchmark: Parse1SplitHard, big text, big match.
|
|
626
623
|
|
|
627
|
-
void Parse1SplitBig2(
|
|
628
|
-
|
|
624
|
+
void Parse1SplitBig2(benchmark::State& state,
|
|
625
|
+
void (*run)(benchmark::State&, const char*,
|
|
626
|
+
const StringPiece&)) {
|
|
629
627
|
std::string s;
|
|
630
628
|
s.append("650-253-");
|
|
631
629
|
s.append(100000, '0');
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
SetBenchmarkItemsProcessed(iters);
|
|
630
|
+
run(state, "[0-9]+.(.*)", s);
|
|
631
|
+
state.SetItemsProcessed(state.iterations());
|
|
635
632
|
}
|
|
636
633
|
|
|
637
|
-
void Parse_CachedSplitBig2_PCRE(
|
|
638
|
-
void Parse_CachedSplitBig2_RE2(
|
|
634
|
+
void Parse_CachedSplitBig2_PCRE(benchmark::State& state) { Parse1SplitBig2(state, SearchParse1CachedPCRE); }
|
|
635
|
+
void Parse_CachedSplitBig2_RE2(benchmark::State& state) { Parse1SplitBig2(state, SearchParse1CachedRE2); }
|
|
639
636
|
|
|
640
637
|
#ifdef USEPCRE
|
|
641
638
|
BENCHMARK(Parse_CachedSplitBig2_PCRE)->ThreadRange(1, NumCPUs());
|
|
@@ -645,16 +642,16 @@ BENCHMARK(Parse_CachedSplitBig2_RE2)->ThreadRange(1, NumCPUs());
|
|
|
645
642
|
// Benchmark: measure time required to parse (but not execute)
|
|
646
643
|
// a simple regular expression.
|
|
647
644
|
|
|
648
|
-
void ParseRegexp(
|
|
649
|
-
for (
|
|
645
|
+
void ParseRegexp(benchmark::State& state, const std::string& regexp) {
|
|
646
|
+
for (auto _ : state) {
|
|
650
647
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
651
648
|
CHECK(re);
|
|
652
649
|
re->Decref();
|
|
653
650
|
}
|
|
654
651
|
}
|
|
655
652
|
|
|
656
|
-
void SimplifyRegexp(
|
|
657
|
-
for (
|
|
653
|
+
void SimplifyRegexp(benchmark::State& state, const std::string& regexp) {
|
|
654
|
+
for (auto _ : state) {
|
|
658
655
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
659
656
|
CHECK(re);
|
|
660
657
|
Regexp* sre = re->Simplify();
|
|
@@ -664,17 +661,17 @@ void SimplifyRegexp(int iters, const std::string& regexp) {
|
|
|
664
661
|
}
|
|
665
662
|
}
|
|
666
663
|
|
|
667
|
-
void NullWalkRegexp(
|
|
664
|
+
void NullWalkRegexp(benchmark::State& state, const std::string& regexp) {
|
|
668
665
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
669
666
|
CHECK(re);
|
|
670
|
-
for (
|
|
667
|
+
for (auto _ : state) {
|
|
671
668
|
re->NullWalk();
|
|
672
669
|
}
|
|
673
670
|
re->Decref();
|
|
674
671
|
}
|
|
675
672
|
|
|
676
|
-
void SimplifyCompileRegexp(
|
|
677
|
-
for (
|
|
673
|
+
void SimplifyCompileRegexp(benchmark::State& state, const std::string& regexp) {
|
|
674
|
+
for (auto _ : state) {
|
|
678
675
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
679
676
|
CHECK(re);
|
|
680
677
|
Regexp* sre = re->Simplify();
|
|
@@ -687,8 +684,8 @@ void SimplifyCompileRegexp(int iters, const std::string& regexp) {
|
|
|
687
684
|
}
|
|
688
685
|
}
|
|
689
686
|
|
|
690
|
-
void CompileRegexp(
|
|
691
|
-
for (
|
|
687
|
+
void CompileRegexp(benchmark::State& state, const std::string& regexp) {
|
|
688
|
+
for (auto _ : state) {
|
|
692
689
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
693
690
|
CHECK(re);
|
|
694
691
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -698,10 +695,10 @@ void CompileRegexp(int iters, const std::string& regexp) {
|
|
|
698
695
|
}
|
|
699
696
|
}
|
|
700
697
|
|
|
701
|
-
void CompileToProg(
|
|
698
|
+
void CompileToProg(benchmark::State& state, const std::string& regexp) {
|
|
702
699
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
703
700
|
CHECK(re);
|
|
704
|
-
for (
|
|
701
|
+
for (auto _ : state) {
|
|
705
702
|
Prog* prog = re->CompileToProg(0);
|
|
706
703
|
CHECK(prog);
|
|
707
704
|
delete prog;
|
|
@@ -709,53 +706,54 @@ void CompileToProg(int iters, const std::string& regexp) {
|
|
|
709
706
|
re->Decref();
|
|
710
707
|
}
|
|
711
708
|
|
|
712
|
-
void CompileByteMap(
|
|
709
|
+
void CompileByteMap(benchmark::State& state, const std::string& regexp) {
|
|
713
710
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
714
711
|
CHECK(re);
|
|
715
712
|
Prog* prog = re->CompileToProg(0);
|
|
716
713
|
CHECK(prog);
|
|
717
|
-
for (
|
|
714
|
+
for (auto _ : state) {
|
|
718
715
|
prog->ComputeByteMap();
|
|
719
716
|
}
|
|
720
717
|
delete prog;
|
|
721
718
|
re->Decref();
|
|
722
719
|
}
|
|
723
720
|
|
|
724
|
-
void CompilePCRE(
|
|
725
|
-
for (
|
|
721
|
+
void CompilePCRE(benchmark::State& state, const std::string& regexp) {
|
|
722
|
+
for (auto _ : state) {
|
|
726
723
|
PCRE re(regexp, PCRE::UTF8);
|
|
727
724
|
CHECK_EQ(re.error(), "");
|
|
728
725
|
}
|
|
729
726
|
}
|
|
730
727
|
|
|
731
|
-
void CompileRE2(
|
|
732
|
-
for (
|
|
728
|
+
void CompileRE2(benchmark::State& state, const std::string& regexp) {
|
|
729
|
+
for (auto _ : state) {
|
|
733
730
|
RE2 re(regexp);
|
|
734
731
|
CHECK_EQ(re.error(), "");
|
|
735
732
|
}
|
|
736
733
|
}
|
|
737
734
|
|
|
738
|
-
void RunBuild(
|
|
739
|
-
void (*run)(
|
|
740
|
-
run(
|
|
741
|
-
|
|
735
|
+
void RunBuild(benchmark::State& state, const std::string& regexp,
|
|
736
|
+
void (*run)(benchmark::State&, const std::string&)) {
|
|
737
|
+
run(state, regexp);
|
|
738
|
+
state.SetItemsProcessed(state.iterations());
|
|
742
739
|
}
|
|
743
740
|
|
|
744
741
|
} // namespace re2
|
|
745
742
|
|
|
746
|
-
|
|
743
|
+
DEFINE_FLAG(std::string, compile_regexp, "(.*)-(\\d+)-of-(\\d+)",
|
|
744
|
+
"regexp for compile benchmarks");
|
|
747
745
|
|
|
748
746
|
namespace re2 {
|
|
749
747
|
|
|
750
|
-
void BM_PCRE_Compile(
|
|
751
|
-
void BM_Regexp_Parse(
|
|
752
|
-
void BM_Regexp_Simplify(
|
|
753
|
-
void BM_CompileToProg(
|
|
754
|
-
void BM_CompileByteMap(
|
|
755
|
-
void BM_Regexp_Compile(
|
|
756
|
-
void BM_Regexp_SimplifyCompile(
|
|
757
|
-
void BM_Regexp_NullWalk(
|
|
758
|
-
void BM_RE2_Compile(
|
|
748
|
+
void BM_PCRE_Compile(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), CompilePCRE); }
|
|
749
|
+
void BM_Regexp_Parse(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), ParseRegexp); }
|
|
750
|
+
void BM_Regexp_Simplify(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), SimplifyRegexp); }
|
|
751
|
+
void BM_CompileToProg(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), CompileToProg); }
|
|
752
|
+
void BM_CompileByteMap(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), CompileByteMap); }
|
|
753
|
+
void BM_Regexp_Compile(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), CompileRegexp); }
|
|
754
|
+
void BM_Regexp_SimplifyCompile(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), SimplifyCompileRegexp); }
|
|
755
|
+
void BM_Regexp_NullWalk(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), NullWalkRegexp); }
|
|
756
|
+
void BM_RE2_Compile(benchmark::State& state) { RunBuild(state, GetFlag(FLAGS_compile_regexp), CompileRE2); }
|
|
759
757
|
|
|
760
758
|
#ifdef USEPCRE
|
|
761
759
|
BENCHMARK(BM_PCRE_Compile)->ThreadRange(1, NumCPUs());
|
|
@@ -771,22 +769,20 @@ BENCHMARK(BM_RE2_Compile)->ThreadRange(1, NumCPUs());
|
|
|
771
769
|
|
|
772
770
|
// Makes text of size nbytes, then calls run to search
|
|
773
771
|
// the text for regexp iters times.
|
|
774
|
-
void SearchPhone(
|
|
775
|
-
StopBenchmarkTiming();
|
|
772
|
+
void SearchPhone(benchmark::State& state, ParseImpl* search) {
|
|
776
773
|
std::string s;
|
|
777
|
-
MakeText(&s,
|
|
774
|
+
MakeText(&s, state.range(0));
|
|
778
775
|
s.append("(650) 253-0001");
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
search(iters, "(\\d{3}-|\\(\\d{3}\\)\\s+)(\\d{3}-\\d{4})", s);
|
|
782
|
-
SetBenchmarkBytesProcessed(static_cast<int64_t>(iters)*nbytes);
|
|
776
|
+
search(state, "(\\d{3}-|\\(\\d{3}\\)\\s+)(\\d{3}-\\d{4})", s);
|
|
777
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
783
778
|
}
|
|
784
779
|
|
|
785
|
-
void SearchPhone_CachedPCRE(
|
|
786
|
-
SearchPhone(
|
|
780
|
+
void SearchPhone_CachedPCRE(benchmark::State& state) {
|
|
781
|
+
SearchPhone(state, SearchParse2CachedPCRE);
|
|
787
782
|
}
|
|
788
|
-
|
|
789
|
-
|
|
783
|
+
|
|
784
|
+
void SearchPhone_CachedRE2(benchmark::State& state) {
|
|
785
|
+
SearchPhone(state, SearchParse2CachedRE2);
|
|
790
786
|
}
|
|
791
787
|
|
|
792
788
|
#ifdef USEPCRE
|
|
@@ -881,9 +877,10 @@ DO24(MY_BENCHMARK_WITH_ARG, CacheFillDFA)
|
|
|
881
877
|
// Expect_match says whether the regexp should be found.
|
|
882
878
|
// Anchored says whether to run an anchored search.
|
|
883
879
|
|
|
884
|
-
void SearchDFA(
|
|
885
|
-
|
|
886
|
-
|
|
880
|
+
void SearchDFA(benchmark::State& state, const char* regexp,
|
|
881
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
882
|
+
bool expect_match) {
|
|
883
|
+
for (auto _ : state) {
|
|
887
884
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
888
885
|
CHECK(re);
|
|
889
886
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -898,9 +895,10 @@ void SearchDFA(int iters, const char* regexp, const StringPiece& text,
|
|
|
898
895
|
}
|
|
899
896
|
}
|
|
900
897
|
|
|
901
|
-
void SearchNFA(
|
|
902
|
-
|
|
903
|
-
|
|
898
|
+
void SearchNFA(benchmark::State& state, const char* regexp,
|
|
899
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
900
|
+
bool expect_match) {
|
|
901
|
+
for (auto _ : state) {
|
|
904
902
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
905
903
|
CHECK(re);
|
|
906
904
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -913,9 +911,10 @@ void SearchNFA(int iters, const char* regexp, const StringPiece& text,
|
|
|
913
911
|
}
|
|
914
912
|
}
|
|
915
913
|
|
|
916
|
-
void SearchOnePass(
|
|
917
|
-
|
|
918
|
-
|
|
914
|
+
void SearchOnePass(benchmark::State& state, const char* regexp,
|
|
915
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
916
|
+
bool expect_match) {
|
|
917
|
+
for (auto _ : state) {
|
|
919
918
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
920
919
|
CHECK(re);
|
|
921
920
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -928,9 +927,10 @@ void SearchOnePass(int iters, const char* regexp, const StringPiece& text,
|
|
|
928
927
|
}
|
|
929
928
|
}
|
|
930
929
|
|
|
931
|
-
void SearchBitState(
|
|
932
|
-
|
|
933
|
-
|
|
930
|
+
void SearchBitState(benchmark::State& state, const char* regexp,
|
|
931
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
932
|
+
bool expect_match) {
|
|
933
|
+
for (auto _ : state) {
|
|
934
934
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
935
935
|
CHECK(re);
|
|
936
936
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -943,9 +943,10 @@ void SearchBitState(int iters, const char* regexp, const StringPiece& text,
|
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
945
|
|
|
946
|
-
void SearchPCRE(
|
|
947
|
-
Prog::Anchor anchor,
|
|
948
|
-
|
|
946
|
+
void SearchPCRE(benchmark::State& state, const char* regexp,
|
|
947
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
948
|
+
bool expect_match) {
|
|
949
|
+
for (auto _ : state) {
|
|
949
950
|
PCRE re(regexp, PCRE::UTF8);
|
|
950
951
|
CHECK_EQ(re.error(), "");
|
|
951
952
|
if (anchor == Prog::kAnchored)
|
|
@@ -955,9 +956,10 @@ void SearchPCRE(int iters, const char* regexp, const StringPiece& text,
|
|
|
955
956
|
}
|
|
956
957
|
}
|
|
957
958
|
|
|
958
|
-
void SearchRE2(
|
|
959
|
-
Prog::Anchor anchor,
|
|
960
|
-
|
|
959
|
+
void SearchRE2(benchmark::State& state, const char* regexp,
|
|
960
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
961
|
+
bool expect_match) {
|
|
962
|
+
for (auto _ : state) {
|
|
961
963
|
RE2 re(regexp);
|
|
962
964
|
CHECK_EQ(re.error(), "");
|
|
963
965
|
if (anchor == Prog::kAnchored)
|
|
@@ -971,13 +973,14 @@ void SearchRE2(int iters, const char* regexp, const StringPiece& text,
|
|
|
971
973
|
// regexp parsing and compiling once. This lets us measure
|
|
972
974
|
// search time without the per-regexp overhead.
|
|
973
975
|
|
|
974
|
-
void SearchCachedDFA(
|
|
975
|
-
Prog::Anchor anchor,
|
|
976
|
+
void SearchCachedDFA(benchmark::State& state, const char* regexp,
|
|
977
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
978
|
+
bool expect_match) {
|
|
976
979
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
977
980
|
CHECK(re);
|
|
978
981
|
Prog* prog = re->CompileToProg(1LL<<31);
|
|
979
982
|
CHECK(prog);
|
|
980
|
-
for (
|
|
983
|
+
for (auto _ : state) {
|
|
981
984
|
bool failed = false;
|
|
982
985
|
CHECK_EQ(prog->SearchDFA(text, StringPiece(), anchor, Prog::kFirstMatch,
|
|
983
986
|
NULL, &failed, NULL),
|
|
@@ -988,13 +991,14 @@ void SearchCachedDFA(int iters, const char* regexp, const StringPiece& text,
|
|
|
988
991
|
re->Decref();
|
|
989
992
|
}
|
|
990
993
|
|
|
991
|
-
void SearchCachedNFA(
|
|
992
|
-
Prog::Anchor anchor,
|
|
994
|
+
void SearchCachedNFA(benchmark::State& state, const char* regexp,
|
|
995
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
996
|
+
bool expect_match) {
|
|
993
997
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
994
998
|
CHECK(re);
|
|
995
999
|
Prog* prog = re->CompileToProg(0);
|
|
996
1000
|
CHECK(prog);
|
|
997
|
-
for (
|
|
1001
|
+
for (auto _ : state) {
|
|
998
1002
|
CHECK_EQ(prog->SearchNFA(text, StringPiece(), anchor, Prog::kFirstMatch,
|
|
999
1003
|
NULL, 0),
|
|
1000
1004
|
expect_match);
|
|
@@ -1003,39 +1007,44 @@ void SearchCachedNFA(int iters, const char* regexp, const StringPiece& text,
|
|
|
1003
1007
|
re->Decref();
|
|
1004
1008
|
}
|
|
1005
1009
|
|
|
1006
|
-
void SearchCachedOnePass(
|
|
1007
|
-
|
|
1010
|
+
void SearchCachedOnePass(benchmark::State& state, const char* regexp,
|
|
1011
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
1012
|
+
bool expect_match) {
|
|
1008
1013
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1009
1014
|
CHECK(re);
|
|
1010
1015
|
Prog* prog = re->CompileToProg(0);
|
|
1011
1016
|
CHECK(prog);
|
|
1012
1017
|
CHECK(prog->IsOnePass());
|
|
1013
|
-
for (
|
|
1018
|
+
for (auto _ : state) {
|
|
1014
1019
|
CHECK_EQ(prog->SearchOnePass(text, text, anchor, Prog::kFirstMatch, NULL, 0),
|
|
1015
1020
|
expect_match);
|
|
1021
|
+
}
|
|
1016
1022
|
delete prog;
|
|
1017
1023
|
re->Decref();
|
|
1018
1024
|
}
|
|
1019
1025
|
|
|
1020
|
-
void SearchCachedBitState(
|
|
1021
|
-
|
|
1026
|
+
void SearchCachedBitState(benchmark::State& state, const char* regexp,
|
|
1027
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
1028
|
+
bool expect_match) {
|
|
1022
1029
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1023
1030
|
CHECK(re);
|
|
1024
1031
|
Prog* prog = re->CompileToProg(0);
|
|
1025
1032
|
CHECK(prog);
|
|
1026
1033
|
CHECK(prog->CanBitState());
|
|
1027
|
-
for (
|
|
1034
|
+
for (auto _ : state) {
|
|
1028
1035
|
CHECK_EQ(prog->SearchBitState(text, text, anchor, Prog::kFirstMatch, NULL, 0),
|
|
1029
1036
|
expect_match);
|
|
1037
|
+
}
|
|
1030
1038
|
delete prog;
|
|
1031
1039
|
re->Decref();
|
|
1032
1040
|
}
|
|
1033
1041
|
|
|
1034
|
-
void SearchCachedPCRE(
|
|
1035
|
-
|
|
1042
|
+
void SearchCachedPCRE(benchmark::State& state, const char* regexp,
|
|
1043
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
1044
|
+
bool expect_match) {
|
|
1036
1045
|
PCRE re(regexp, PCRE::UTF8);
|
|
1037
1046
|
CHECK_EQ(re.error(), "");
|
|
1038
|
-
for (
|
|
1047
|
+
for (auto _ : state) {
|
|
1039
1048
|
if (anchor == Prog::kAnchored)
|
|
1040
1049
|
CHECK_EQ(PCRE::FullMatch(text, re), expect_match);
|
|
1041
1050
|
else
|
|
@@ -1043,11 +1052,12 @@ void SearchCachedPCRE(int iters, const char* regexp, const StringPiece& text,
|
|
|
1043
1052
|
}
|
|
1044
1053
|
}
|
|
1045
1054
|
|
|
1046
|
-
void SearchCachedRE2(
|
|
1047
|
-
Prog::Anchor anchor,
|
|
1055
|
+
void SearchCachedRE2(benchmark::State& state, const char* regexp,
|
|
1056
|
+
const StringPiece& text, Prog::Anchor anchor,
|
|
1057
|
+
bool expect_match) {
|
|
1048
1058
|
RE2 re(regexp);
|
|
1049
1059
|
CHECK_EQ(re.error(), "");
|
|
1050
|
-
for (
|
|
1060
|
+
for (auto _ : state) {
|
|
1051
1061
|
if (anchor == Prog::kAnchored)
|
|
1052
1062
|
CHECK_EQ(RE2::FullMatch(text, re), expect_match);
|
|
1053
1063
|
else
|
|
@@ -1055,12 +1065,12 @@ void SearchCachedRE2(int iters, const char* regexp, const StringPiece& text,
|
|
|
1055
1065
|
}
|
|
1056
1066
|
}
|
|
1057
1067
|
|
|
1058
|
-
|
|
1059
1068
|
// Runs implementation to full match regexp against text,
|
|
1060
1069
|
// extracting three submatches. Expects match always.
|
|
1061
1070
|
|
|
1062
|
-
void Parse3NFA(
|
|
1063
|
-
|
|
1071
|
+
void Parse3NFA(benchmark::State& state, const char* regexp,
|
|
1072
|
+
const StringPiece& text) {
|
|
1073
|
+
for (auto _ : state) {
|
|
1064
1074
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1065
1075
|
CHECK(re);
|
|
1066
1076
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1073,8 +1083,9 @@ void Parse3NFA(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1073
1083
|
}
|
|
1074
1084
|
}
|
|
1075
1085
|
|
|
1076
|
-
void Parse3OnePass(
|
|
1077
|
-
|
|
1086
|
+
void Parse3OnePass(benchmark::State& state, const char* regexp,
|
|
1087
|
+
const StringPiece& text) {
|
|
1088
|
+
for (auto _ : state) {
|
|
1078
1089
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1079
1090
|
CHECK(re);
|
|
1080
1091
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1087,8 +1098,9 @@ void Parse3OnePass(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1087
1098
|
}
|
|
1088
1099
|
}
|
|
1089
1100
|
|
|
1090
|
-
void Parse3BitState(
|
|
1091
|
-
|
|
1101
|
+
void Parse3BitState(benchmark::State& state, const char* regexp,
|
|
1102
|
+
const StringPiece& text) {
|
|
1103
|
+
for (auto _ : state) {
|
|
1092
1104
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1093
1105
|
CHECK(re);
|
|
1094
1106
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1101,8 +1113,9 @@ void Parse3BitState(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1101
1113
|
}
|
|
1102
1114
|
}
|
|
1103
1115
|
|
|
1104
|
-
void Parse3Backtrack(
|
|
1105
|
-
|
|
1116
|
+
void Parse3Backtrack(benchmark::State& state, const char* regexp,
|
|
1117
|
+
const StringPiece& text) {
|
|
1118
|
+
for (auto _ : state) {
|
|
1106
1119
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1107
1120
|
CHECK(re);
|
|
1108
1121
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1114,8 +1127,9 @@ void Parse3Backtrack(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1114
1127
|
}
|
|
1115
1128
|
}
|
|
1116
1129
|
|
|
1117
|
-
void Parse3PCRE(
|
|
1118
|
-
|
|
1130
|
+
void Parse3PCRE(benchmark::State& state, const char* regexp,
|
|
1131
|
+
const StringPiece& text) {
|
|
1132
|
+
for (auto _ : state) {
|
|
1119
1133
|
PCRE re(regexp, PCRE::UTF8);
|
|
1120
1134
|
CHECK_EQ(re.error(), "");
|
|
1121
1135
|
StringPiece sp1, sp2, sp3;
|
|
@@ -1123,8 +1137,9 @@ void Parse3PCRE(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1123
1137
|
}
|
|
1124
1138
|
}
|
|
1125
1139
|
|
|
1126
|
-
void Parse3RE2(
|
|
1127
|
-
|
|
1140
|
+
void Parse3RE2(benchmark::State& state, const char* regexp,
|
|
1141
|
+
const StringPiece& text) {
|
|
1142
|
+
for (auto _ : state) {
|
|
1128
1143
|
RE2 re(regexp);
|
|
1129
1144
|
CHECK_EQ(re.error(), "");
|
|
1130
1145
|
StringPiece sp1, sp2, sp3;
|
|
@@ -1132,13 +1147,14 @@ void Parse3RE2(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1132
1147
|
}
|
|
1133
1148
|
}
|
|
1134
1149
|
|
|
1135
|
-
void Parse3CachedNFA(
|
|
1150
|
+
void Parse3CachedNFA(benchmark::State& state, const char* regexp,
|
|
1151
|
+
const StringPiece& text) {
|
|
1136
1152
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1137
1153
|
CHECK(re);
|
|
1138
1154
|
Prog* prog = re->CompileToProg(0);
|
|
1139
1155
|
CHECK(prog);
|
|
1140
1156
|
StringPiece sp[4]; // 4 because sp[0] is whole match.
|
|
1141
|
-
for (
|
|
1157
|
+
for (auto _ : state) {
|
|
1142
1158
|
CHECK(prog->SearchNFA(text, StringPiece(), Prog::kAnchored,
|
|
1143
1159
|
Prog::kFullMatch, sp, 4));
|
|
1144
1160
|
}
|
|
@@ -1146,68 +1162,76 @@ void Parse3CachedNFA(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1146
1162
|
re->Decref();
|
|
1147
1163
|
}
|
|
1148
1164
|
|
|
1149
|
-
void Parse3CachedOnePass(
|
|
1165
|
+
void Parse3CachedOnePass(benchmark::State& state, const char* regexp,
|
|
1166
|
+
const StringPiece& text) {
|
|
1150
1167
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1151
1168
|
CHECK(re);
|
|
1152
1169
|
Prog* prog = re->CompileToProg(0);
|
|
1153
1170
|
CHECK(prog);
|
|
1154
1171
|
CHECK(prog->IsOnePass());
|
|
1155
1172
|
StringPiece sp[4]; // 4 because sp[0] is whole match.
|
|
1156
|
-
for (
|
|
1173
|
+
for (auto _ : state) {
|
|
1157
1174
|
CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4));
|
|
1175
|
+
}
|
|
1158
1176
|
delete prog;
|
|
1159
1177
|
re->Decref();
|
|
1160
1178
|
}
|
|
1161
1179
|
|
|
1162
|
-
void Parse3CachedBitState(
|
|
1180
|
+
void Parse3CachedBitState(benchmark::State& state, const char* regexp,
|
|
1181
|
+
const StringPiece& text) {
|
|
1163
1182
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1164
1183
|
CHECK(re);
|
|
1165
1184
|
Prog* prog = re->CompileToProg(0);
|
|
1166
1185
|
CHECK(prog);
|
|
1167
1186
|
CHECK(prog->CanBitState());
|
|
1168
1187
|
StringPiece sp[4]; // 4 because sp[0] is whole match.
|
|
1169
|
-
for (
|
|
1188
|
+
for (auto _ : state) {
|
|
1170
1189
|
CHECK(prog->SearchBitState(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4));
|
|
1190
|
+
}
|
|
1171
1191
|
delete prog;
|
|
1172
1192
|
re->Decref();
|
|
1173
1193
|
}
|
|
1174
1194
|
|
|
1175
|
-
void Parse3CachedBacktrack(
|
|
1195
|
+
void Parse3CachedBacktrack(benchmark::State& state, const char* regexp,
|
|
1196
|
+
const StringPiece& text) {
|
|
1176
1197
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1177
1198
|
CHECK(re);
|
|
1178
1199
|
Prog* prog = re->CompileToProg(0);
|
|
1179
1200
|
CHECK(prog);
|
|
1180
1201
|
StringPiece sp[4]; // 4 because sp[0] is whole match.
|
|
1181
|
-
for (
|
|
1202
|
+
for (auto _ : state) {
|
|
1182
1203
|
CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4));
|
|
1204
|
+
}
|
|
1183
1205
|
delete prog;
|
|
1184
1206
|
re->Decref();
|
|
1185
1207
|
}
|
|
1186
1208
|
|
|
1187
|
-
void Parse3CachedPCRE(
|
|
1209
|
+
void Parse3CachedPCRE(benchmark::State& state, const char* regexp,
|
|
1210
|
+
const StringPiece& text) {
|
|
1188
1211
|
PCRE re(regexp, PCRE::UTF8);
|
|
1189
1212
|
CHECK_EQ(re.error(), "");
|
|
1190
1213
|
StringPiece sp1, sp2, sp3;
|
|
1191
|
-
for (
|
|
1214
|
+
for (auto _ : state) {
|
|
1192
1215
|
CHECK(PCRE::FullMatch(text, re, &sp1, &sp2, &sp3));
|
|
1193
1216
|
}
|
|
1194
1217
|
}
|
|
1195
1218
|
|
|
1196
|
-
void Parse3CachedRE2(
|
|
1219
|
+
void Parse3CachedRE2(benchmark::State& state, const char* regexp,
|
|
1220
|
+
const StringPiece& text) {
|
|
1197
1221
|
RE2 re(regexp);
|
|
1198
1222
|
CHECK_EQ(re.error(), "");
|
|
1199
1223
|
StringPiece sp1, sp2, sp3;
|
|
1200
|
-
for (
|
|
1224
|
+
for (auto _ : state) {
|
|
1201
1225
|
CHECK(RE2::FullMatch(text, re, &sp1, &sp2, &sp3));
|
|
1202
1226
|
}
|
|
1203
1227
|
}
|
|
1204
1228
|
|
|
1205
|
-
|
|
1206
1229
|
// Runs implementation to full match regexp against text,
|
|
1207
1230
|
// extracting three submatches. Expects match always.
|
|
1208
1231
|
|
|
1209
|
-
void Parse1NFA(
|
|
1210
|
-
|
|
1232
|
+
void Parse1NFA(benchmark::State& state, const char* regexp,
|
|
1233
|
+
const StringPiece& text) {
|
|
1234
|
+
for (auto _ : state) {
|
|
1211
1235
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1212
1236
|
CHECK(re);
|
|
1213
1237
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1220,8 +1244,9 @@ void Parse1NFA(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1220
1244
|
}
|
|
1221
1245
|
}
|
|
1222
1246
|
|
|
1223
|
-
void Parse1OnePass(
|
|
1224
|
-
|
|
1247
|
+
void Parse1OnePass(benchmark::State& state, const char* regexp,
|
|
1248
|
+
const StringPiece& text) {
|
|
1249
|
+
for (auto _ : state) {
|
|
1225
1250
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1226
1251
|
CHECK(re);
|
|
1227
1252
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1234,8 +1259,9 @@ void Parse1OnePass(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1234
1259
|
}
|
|
1235
1260
|
}
|
|
1236
1261
|
|
|
1237
|
-
void Parse1BitState(
|
|
1238
|
-
|
|
1262
|
+
void Parse1BitState(benchmark::State& state, const char* regexp,
|
|
1263
|
+
const StringPiece& text) {
|
|
1264
|
+
for (auto _ : state) {
|
|
1239
1265
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1240
1266
|
CHECK(re);
|
|
1241
1267
|
Prog* prog = re->CompileToProg(0);
|
|
@@ -1248,8 +1274,9 @@ void Parse1BitState(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1248
1274
|
}
|
|
1249
1275
|
}
|
|
1250
1276
|
|
|
1251
|
-
void Parse1PCRE(
|
|
1252
|
-
|
|
1277
|
+
void Parse1PCRE(benchmark::State& state, const char* regexp,
|
|
1278
|
+
const StringPiece& text) {
|
|
1279
|
+
for (auto _ : state) {
|
|
1253
1280
|
PCRE re(regexp, PCRE::UTF8);
|
|
1254
1281
|
CHECK_EQ(re.error(), "");
|
|
1255
1282
|
StringPiece sp1;
|
|
@@ -1257,8 +1284,9 @@ void Parse1PCRE(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1257
1284
|
}
|
|
1258
1285
|
}
|
|
1259
1286
|
|
|
1260
|
-
void Parse1RE2(
|
|
1261
|
-
|
|
1287
|
+
void Parse1RE2(benchmark::State& state, const char* regexp,
|
|
1288
|
+
const StringPiece& text) {
|
|
1289
|
+
for (auto _ : state) {
|
|
1262
1290
|
RE2 re(regexp);
|
|
1263
1291
|
CHECK_EQ(re.error(), "");
|
|
1264
1292
|
StringPiece sp1;
|
|
@@ -1266,13 +1294,14 @@ void Parse1RE2(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1266
1294
|
}
|
|
1267
1295
|
}
|
|
1268
1296
|
|
|
1269
|
-
void Parse1CachedNFA(
|
|
1297
|
+
void Parse1CachedNFA(benchmark::State& state, const char* regexp,
|
|
1298
|
+
const StringPiece& text) {
|
|
1270
1299
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1271
1300
|
CHECK(re);
|
|
1272
1301
|
Prog* prog = re->CompileToProg(0);
|
|
1273
1302
|
CHECK(prog);
|
|
1274
1303
|
StringPiece sp[2]; // 2 because sp[0] is whole match.
|
|
1275
|
-
for (
|
|
1304
|
+
for (auto _ : state) {
|
|
1276
1305
|
CHECK(prog->SearchNFA(text, StringPiece(), Prog::kAnchored,
|
|
1277
1306
|
Prog::kFullMatch, sp, 2));
|
|
1278
1307
|
}
|
|
@@ -1280,112 +1309,120 @@ void Parse1CachedNFA(int iters, const char* regexp, const StringPiece& text) {
|
|
|
1280
1309
|
re->Decref();
|
|
1281
1310
|
}
|
|
1282
1311
|
|
|
1283
|
-
void Parse1CachedOnePass(
|
|
1312
|
+
void Parse1CachedOnePass(benchmark::State& state, const char* regexp,
|
|
1313
|
+
const StringPiece& text) {
|
|
1284
1314
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1285
1315
|
CHECK(re);
|
|
1286
1316
|
Prog* prog = re->CompileToProg(0);
|
|
1287
1317
|
CHECK(prog);
|
|
1288
1318
|
CHECK(prog->IsOnePass());
|
|
1289
1319
|
StringPiece sp[2]; // 2 because sp[0] is whole match.
|
|
1290
|
-
for (
|
|
1320
|
+
for (auto _ : state) {
|
|
1291
1321
|
CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2));
|
|
1322
|
+
}
|
|
1292
1323
|
delete prog;
|
|
1293
1324
|
re->Decref();
|
|
1294
1325
|
}
|
|
1295
1326
|
|
|
1296
|
-
void Parse1CachedBitState(
|
|
1327
|
+
void Parse1CachedBitState(benchmark::State& state, const char* regexp,
|
|
1328
|
+
const StringPiece& text) {
|
|
1297
1329
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1298
1330
|
CHECK(re);
|
|
1299
1331
|
Prog* prog = re->CompileToProg(0);
|
|
1300
1332
|
CHECK(prog);
|
|
1301
1333
|
CHECK(prog->CanBitState());
|
|
1302
1334
|
StringPiece sp[2]; // 2 because sp[0] is whole match.
|
|
1303
|
-
for (
|
|
1335
|
+
for (auto _ : state) {
|
|
1304
1336
|
CHECK(prog->SearchBitState(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2));
|
|
1337
|
+
}
|
|
1305
1338
|
delete prog;
|
|
1306
1339
|
re->Decref();
|
|
1307
1340
|
}
|
|
1308
1341
|
|
|
1309
|
-
void Parse1CachedBacktrack(
|
|
1342
|
+
void Parse1CachedBacktrack(benchmark::State& state, const char* regexp,
|
|
1343
|
+
const StringPiece& text) {
|
|
1310
1344
|
Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL);
|
|
1311
1345
|
CHECK(re);
|
|
1312
1346
|
Prog* prog = re->CompileToProg(0);
|
|
1313
1347
|
CHECK(prog);
|
|
1314
1348
|
StringPiece sp[2]; // 2 because sp[0] is whole match.
|
|
1315
|
-
for (
|
|
1349
|
+
for (auto _ : state) {
|
|
1316
1350
|
CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2));
|
|
1351
|
+
}
|
|
1317
1352
|
delete prog;
|
|
1318
1353
|
re->Decref();
|
|
1319
1354
|
}
|
|
1320
1355
|
|
|
1321
|
-
void Parse1CachedPCRE(
|
|
1356
|
+
void Parse1CachedPCRE(benchmark::State& state, const char* regexp,
|
|
1357
|
+
const StringPiece& text) {
|
|
1322
1358
|
PCRE re(regexp, PCRE::UTF8);
|
|
1323
1359
|
CHECK_EQ(re.error(), "");
|
|
1324
1360
|
StringPiece sp1;
|
|
1325
|
-
for (
|
|
1361
|
+
for (auto _ : state) {
|
|
1326
1362
|
CHECK(PCRE::FullMatch(text, re, &sp1));
|
|
1327
1363
|
}
|
|
1328
1364
|
}
|
|
1329
1365
|
|
|
1330
|
-
void Parse1CachedRE2(
|
|
1366
|
+
void Parse1CachedRE2(benchmark::State& state, const char* regexp,
|
|
1367
|
+
const StringPiece& text) {
|
|
1331
1368
|
RE2 re(regexp);
|
|
1332
1369
|
CHECK_EQ(re.error(), "");
|
|
1333
1370
|
StringPiece sp1;
|
|
1334
|
-
for (
|
|
1371
|
+
for (auto _ : state) {
|
|
1335
1372
|
CHECK(RE2::FullMatch(text, re, &sp1));
|
|
1336
1373
|
}
|
|
1337
1374
|
}
|
|
1338
1375
|
|
|
1339
|
-
void SearchParse2CachedPCRE(
|
|
1376
|
+
void SearchParse2CachedPCRE(benchmark::State& state, const char* regexp,
|
|
1340
1377
|
const StringPiece& text) {
|
|
1341
1378
|
PCRE re(regexp, PCRE::UTF8);
|
|
1342
1379
|
CHECK_EQ(re.error(), "");
|
|
1343
|
-
for (
|
|
1380
|
+
for (auto _ : state) {
|
|
1344
1381
|
StringPiece sp1, sp2;
|
|
1345
1382
|
CHECK(PCRE::PartialMatch(text, re, &sp1, &sp2));
|
|
1346
1383
|
}
|
|
1347
1384
|
}
|
|
1348
1385
|
|
|
1349
|
-
void SearchParse2CachedRE2(
|
|
1386
|
+
void SearchParse2CachedRE2(benchmark::State& state, const char* regexp,
|
|
1350
1387
|
const StringPiece& text) {
|
|
1351
1388
|
RE2 re(regexp);
|
|
1352
1389
|
CHECK_EQ(re.error(), "");
|
|
1353
|
-
for (
|
|
1390
|
+
for (auto _ : state) {
|
|
1354
1391
|
StringPiece sp1, sp2;
|
|
1355
1392
|
CHECK(RE2::PartialMatch(text, re, &sp1, &sp2));
|
|
1356
1393
|
}
|
|
1357
1394
|
}
|
|
1358
1395
|
|
|
1359
|
-
void SearchParse1CachedPCRE(
|
|
1396
|
+
void SearchParse1CachedPCRE(benchmark::State& state, const char* regexp,
|
|
1360
1397
|
const StringPiece& text) {
|
|
1361
1398
|
PCRE re(regexp, PCRE::UTF8);
|
|
1362
1399
|
CHECK_EQ(re.error(), "");
|
|
1363
|
-
for (
|
|
1400
|
+
for (auto _ : state) {
|
|
1364
1401
|
StringPiece sp1;
|
|
1365
1402
|
CHECK(PCRE::PartialMatch(text, re, &sp1));
|
|
1366
1403
|
}
|
|
1367
1404
|
}
|
|
1368
1405
|
|
|
1369
|
-
void SearchParse1CachedRE2(
|
|
1406
|
+
void SearchParse1CachedRE2(benchmark::State& state, const char* regexp,
|
|
1370
1407
|
const StringPiece& text) {
|
|
1371
1408
|
RE2 re(regexp);
|
|
1372
1409
|
CHECK_EQ(re.error(), "");
|
|
1373
|
-
for (
|
|
1410
|
+
for (auto _ : state) {
|
|
1374
1411
|
StringPiece sp1;
|
|
1375
1412
|
CHECK(RE2::PartialMatch(text, re, &sp1));
|
|
1376
1413
|
}
|
|
1377
1414
|
}
|
|
1378
1415
|
|
|
1379
|
-
void EmptyPartialMatchPCRE(
|
|
1416
|
+
void EmptyPartialMatchPCRE(benchmark::State& state) {
|
|
1380
1417
|
PCRE re("");
|
|
1381
|
-
for (
|
|
1418
|
+
for (auto _ : state) {
|
|
1382
1419
|
PCRE::PartialMatch("", re);
|
|
1383
1420
|
}
|
|
1384
1421
|
}
|
|
1385
1422
|
|
|
1386
|
-
void EmptyPartialMatchRE2(
|
|
1423
|
+
void EmptyPartialMatchRE2(benchmark::State& state) {
|
|
1387
1424
|
RE2 re("");
|
|
1388
|
-
for (
|
|
1425
|
+
for (auto _ : state) {
|
|
1389
1426
|
RE2::PartialMatch("", re);
|
|
1390
1427
|
}
|
|
1391
1428
|
}
|
|
@@ -1394,16 +1431,16 @@ BENCHMARK(EmptyPartialMatchPCRE)->ThreadRange(1, NumCPUs());
|
|
|
1394
1431
|
#endif
|
|
1395
1432
|
BENCHMARK(EmptyPartialMatchRE2)->ThreadRange(1, NumCPUs());
|
|
1396
1433
|
|
|
1397
|
-
void SimplePartialMatchPCRE(
|
|
1434
|
+
void SimplePartialMatchPCRE(benchmark::State& state) {
|
|
1398
1435
|
PCRE re("abcdefg");
|
|
1399
|
-
for (
|
|
1436
|
+
for (auto _ : state) {
|
|
1400
1437
|
PCRE::PartialMatch("abcdefg", re);
|
|
1401
1438
|
}
|
|
1402
1439
|
}
|
|
1403
1440
|
|
|
1404
|
-
void SimplePartialMatchRE2(
|
|
1441
|
+
void SimplePartialMatchRE2(benchmark::State& state) {
|
|
1405
1442
|
RE2 re("abcdefg");
|
|
1406
|
-
for (
|
|
1443
|
+
for (auto _ : state) {
|
|
1407
1444
|
RE2::PartialMatch("abcdefg", re);
|
|
1408
1445
|
}
|
|
1409
1446
|
}
|
|
@@ -1416,18 +1453,18 @@ static std::string http_text =
|
|
|
1416
1453
|
"GET /asdfhjasdhfasdlfhasdflkjasdfkljasdhflaskdjhf"
|
|
1417
1454
|
"alksdjfhasdlkfhasdlkjfhasdljkfhadsjklf HTTP/1.1";
|
|
1418
1455
|
|
|
1419
|
-
void HTTPPartialMatchPCRE(
|
|
1456
|
+
void HTTPPartialMatchPCRE(benchmark::State& state) {
|
|
1420
1457
|
StringPiece a;
|
|
1421
1458
|
PCRE re("(?-s)^(?:GET|POST) +([^ ]+) HTTP");
|
|
1422
|
-
for (
|
|
1459
|
+
for (auto _ : state) {
|
|
1423
1460
|
PCRE::PartialMatch(http_text, re, &a);
|
|
1424
1461
|
}
|
|
1425
1462
|
}
|
|
1426
1463
|
|
|
1427
|
-
void HTTPPartialMatchRE2(
|
|
1464
|
+
void HTTPPartialMatchRE2(benchmark::State& state) {
|
|
1428
1465
|
StringPiece a;
|
|
1429
1466
|
RE2 re("(?-s)^(?:GET|POST) +([^ ]+) HTTP");
|
|
1430
|
-
for (
|
|
1467
|
+
for (auto _ : state) {
|
|
1431
1468
|
RE2::PartialMatch(http_text, re, &a);
|
|
1432
1469
|
}
|
|
1433
1470
|
}
|
|
@@ -1440,18 +1477,18 @@ BENCHMARK(HTTPPartialMatchRE2)->ThreadRange(1, NumCPUs());
|
|
|
1440
1477
|
static std::string smallhttp_text =
|
|
1441
1478
|
"GET /abc HTTP/1.1";
|
|
1442
1479
|
|
|
1443
|
-
void SmallHTTPPartialMatchPCRE(
|
|
1480
|
+
void SmallHTTPPartialMatchPCRE(benchmark::State& state) {
|
|
1444
1481
|
StringPiece a;
|
|
1445
1482
|
PCRE re("(?-s)^(?:GET|POST) +([^ ]+) HTTP");
|
|
1446
|
-
for (
|
|
1483
|
+
for (auto _ : state) {
|
|
1447
1484
|
PCRE::PartialMatch(smallhttp_text, re, &a);
|
|
1448
1485
|
}
|
|
1449
1486
|
}
|
|
1450
1487
|
|
|
1451
|
-
void SmallHTTPPartialMatchRE2(
|
|
1488
|
+
void SmallHTTPPartialMatchRE2(benchmark::State& state) {
|
|
1452
1489
|
StringPiece a;
|
|
1453
1490
|
RE2 re("(?-s)^(?:GET|POST) +([^ ]+) HTTP");
|
|
1454
|
-
for (
|
|
1491
|
+
for (auto _ : state) {
|
|
1455
1492
|
RE2::PartialMatch(smallhttp_text, re, &a);
|
|
1456
1493
|
}
|
|
1457
1494
|
}
|
|
@@ -1461,18 +1498,18 @@ BENCHMARK(SmallHTTPPartialMatchPCRE)->ThreadRange(1, NumCPUs());
|
|
|
1461
1498
|
#endif
|
|
1462
1499
|
BENCHMARK(SmallHTTPPartialMatchRE2)->ThreadRange(1, NumCPUs());
|
|
1463
1500
|
|
|
1464
|
-
void DotMatchPCRE(
|
|
1501
|
+
void DotMatchPCRE(benchmark::State& state) {
|
|
1465
1502
|
StringPiece a;
|
|
1466
1503
|
PCRE re("(?-s)^(.+)");
|
|
1467
|
-
for (
|
|
1504
|
+
for (auto _ : state) {
|
|
1468
1505
|
PCRE::PartialMatch(http_text, re, &a);
|
|
1469
1506
|
}
|
|
1470
1507
|
}
|
|
1471
1508
|
|
|
1472
|
-
void DotMatchRE2(
|
|
1509
|
+
void DotMatchRE2(benchmark::State& state) {
|
|
1473
1510
|
StringPiece a;
|
|
1474
1511
|
RE2 re("(?-s)^(.+)");
|
|
1475
|
-
for (
|
|
1512
|
+
for (auto _ : state) {
|
|
1476
1513
|
RE2::PartialMatch(http_text, re, &a);
|
|
1477
1514
|
}
|
|
1478
1515
|
}
|
|
@@ -1482,18 +1519,18 @@ BENCHMARK(DotMatchPCRE)->ThreadRange(1, NumCPUs());
|
|
|
1482
1519
|
#endif
|
|
1483
1520
|
BENCHMARK(DotMatchRE2)->ThreadRange(1, NumCPUs());
|
|
1484
1521
|
|
|
1485
|
-
void ASCIIMatchPCRE(
|
|
1522
|
+
void ASCIIMatchPCRE(benchmark::State& state) {
|
|
1486
1523
|
StringPiece a;
|
|
1487
1524
|
PCRE re("(?-s)^([ -~]+)");
|
|
1488
|
-
for (
|
|
1525
|
+
for (auto _ : state) {
|
|
1489
1526
|
PCRE::PartialMatch(http_text, re, &a);
|
|
1490
1527
|
}
|
|
1491
1528
|
}
|
|
1492
1529
|
|
|
1493
|
-
void ASCIIMatchRE2(
|
|
1530
|
+
void ASCIIMatchRE2(benchmark::State& state) {
|
|
1494
1531
|
StringPiece a;
|
|
1495
1532
|
RE2 re("(?-s)^([ -~]+)");
|
|
1496
|
-
for (
|
|
1533
|
+
for (auto _ : state) {
|
|
1497
1534
|
RE2::PartialMatch(http_text, re, &a);
|
|
1498
1535
|
}
|
|
1499
1536
|
}
|
|
@@ -1503,40 +1540,36 @@ BENCHMARK(ASCIIMatchPCRE)->ThreadRange(1, NumCPUs());
|
|
|
1503
1540
|
#endif
|
|
1504
1541
|
BENCHMARK(ASCIIMatchRE2)->ThreadRange(1, NumCPUs());
|
|
1505
1542
|
|
|
1506
|
-
void FullMatchPCRE(
|
|
1507
|
-
StopBenchmarkTiming();
|
|
1543
|
+
void FullMatchPCRE(benchmark::State& state, const char *regexp) {
|
|
1508
1544
|
std::string s;
|
|
1509
|
-
MakeText(&s,
|
|
1545
|
+
MakeText(&s, state.range(0));
|
|
1510
1546
|
s += "ABCDEFGHIJ";
|
|
1511
|
-
BenchmarkMemoryUsage();
|
|
1512
1547
|
PCRE re(regexp);
|
|
1513
|
-
|
|
1514
|
-
for (int i = 0; i < iter; i++)
|
|
1548
|
+
for (auto _ : state) {
|
|
1515
1549
|
CHECK(PCRE::FullMatch(s, re));
|
|
1516
|
-
|
|
1550
|
+
}
|
|
1551
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
1517
1552
|
}
|
|
1518
1553
|
|
|
1519
|
-
void FullMatchRE2(
|
|
1520
|
-
StopBenchmarkTiming();
|
|
1554
|
+
void FullMatchRE2(benchmark::State& state, const char *regexp) {
|
|
1521
1555
|
std::string s;
|
|
1522
|
-
MakeText(&s,
|
|
1556
|
+
MakeText(&s, state.range(0));
|
|
1523
1557
|
s += "ABCDEFGHIJ";
|
|
1524
|
-
BenchmarkMemoryUsage();
|
|
1525
1558
|
RE2 re(regexp, RE2::Latin1);
|
|
1526
|
-
|
|
1527
|
-
for (int i = 0; i < iter; i++)
|
|
1559
|
+
for (auto _ : state) {
|
|
1528
1560
|
CHECK(RE2::FullMatch(s, re));
|
|
1529
|
-
|
|
1561
|
+
}
|
|
1562
|
+
state.SetBytesProcessed(state.iterations() * state.range(0));
|
|
1530
1563
|
}
|
|
1531
1564
|
|
|
1532
|
-
void FullMatch_DotStar_CachedPCRE(
|
|
1533
|
-
void FullMatch_DotStar_CachedRE2(
|
|
1565
|
+
void FullMatch_DotStar_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s).*"); }
|
|
1566
|
+
void FullMatch_DotStar_CachedRE2(benchmark::State& state) { FullMatchRE2(state, "(?s).*"); }
|
|
1534
1567
|
|
|
1535
|
-
void FullMatch_DotStarDollar_CachedPCRE(
|
|
1536
|
-
void FullMatch_DotStarDollar_CachedRE2(
|
|
1568
|
+
void FullMatch_DotStarDollar_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s).*$"); }
|
|
1569
|
+
void FullMatch_DotStarDollar_CachedRE2(benchmark::State& state) { FullMatchRE2(state, "(?s).*$"); }
|
|
1537
1570
|
|
|
1538
|
-
void FullMatch_DotStarCapture_CachedPCRE(
|
|
1539
|
-
void FullMatch_DotStarCapture_CachedRE2(
|
|
1571
|
+
void FullMatch_DotStarCapture_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s)((.*)()()($))"); }
|
|
1572
|
+
void FullMatch_DotStarCapture_CachedRE2(benchmark::State& state) { FullMatchRE2(state, "(?s)((.*)()()($))"); }
|
|
1540
1573
|
|
|
1541
1574
|
#ifdef USEPCRE
|
|
1542
1575
|
BENCHMARK_RANGE(FullMatch_DotStar_CachedPCRE, 8, 2<<20);
|
|
@@ -1553,29 +1586,27 @@ BENCHMARK_RANGE(FullMatch_DotStarCapture_CachedPCRE, 8, 2<<20);
|
|
|
1553
1586
|
#endif
|
|
1554
1587
|
BENCHMARK_RANGE(FullMatch_DotStarCapture_CachedRE2, 8, 2<<20);
|
|
1555
1588
|
|
|
1556
|
-
void PossibleMatchRangeCommon(
|
|
1557
|
-
StopBenchmarkTiming();
|
|
1589
|
+
void PossibleMatchRangeCommon(benchmark::State& state, const char* regexp) {
|
|
1558
1590
|
RE2 re(regexp);
|
|
1559
|
-
StartBenchmarkTiming();
|
|
1560
1591
|
std::string min;
|
|
1561
1592
|
std::string max;
|
|
1562
1593
|
const int kMaxLen = 16;
|
|
1563
|
-
for (
|
|
1594
|
+
for (auto _ : state) {
|
|
1564
1595
|
CHECK(re.PossibleMatchRange(&min, &max, kMaxLen));
|
|
1565
1596
|
}
|
|
1566
1597
|
}
|
|
1567
1598
|
|
|
1568
|
-
void PossibleMatchRange_Trivial(
|
|
1569
|
-
PossibleMatchRangeCommon(
|
|
1599
|
+
void PossibleMatchRange_Trivial(benchmark::State& state) {
|
|
1600
|
+
PossibleMatchRangeCommon(state, ".*");
|
|
1570
1601
|
}
|
|
1571
|
-
void PossibleMatchRange_Complex(
|
|
1572
|
-
PossibleMatchRangeCommon(
|
|
1602
|
+
void PossibleMatchRange_Complex(benchmark::State& state) {
|
|
1603
|
+
PossibleMatchRangeCommon(state, "^abc[def]?[gh]{1,2}.*");
|
|
1573
1604
|
}
|
|
1574
|
-
void PossibleMatchRange_Prefix(
|
|
1575
|
-
PossibleMatchRangeCommon(
|
|
1605
|
+
void PossibleMatchRange_Prefix(benchmark::State& state) {
|
|
1606
|
+
PossibleMatchRangeCommon(state, "^some_random_prefix.*");
|
|
1576
1607
|
}
|
|
1577
|
-
void PossibleMatchRange_NoProg(
|
|
1578
|
-
PossibleMatchRangeCommon(
|
|
1608
|
+
void PossibleMatchRange_NoProg(benchmark::State& state) {
|
|
1609
|
+
PossibleMatchRangeCommon(state, "^some_random_string$");
|
|
1579
1610
|
}
|
|
1580
1611
|
|
|
1581
1612
|
BENCHMARK(PossibleMatchRange_Trivial);
|