-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperpos.cpp
More file actions
50 lines (46 loc) · 1.78 KB
/
Copy pathperpos.cpp
File metadata and controls
50 lines (46 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Le cout par position rejetee depend-il de la complexite du motif,
// ou est-ce un surcout fixe par tentative ?
#define NOMINMAX
#include <windows.h>
#include <chrono>
#include <cstdio>
#include <regex>
#include <string>
typedef std::chrono::steady_clock clk;
static const size_t N = 303104;
static std::string plain;
static void bench(const char* name, const char* pattern) {
std::regex rx(pattern, std::regex::ECMAScript | std::regex::optimize);
auto once = [&]() -> long {
long n = 0;
for (auto it = std::sregex_iterator(plain.begin(), plain.end(), rx);
it != std::sregex_iterator(); ++it) ++n;
return n;
};
long m = once();
auto t0 = clk::now();
int passes = 0;
double el = 0;
do { m = once(); ++passes; el = std::chrono::duration<double>(clk::now() - t0).count(); }
while (el < 1.0);
double ms = el / passes * 1000.0;
printf(" %-34s %8.2f ms %8.1f ns/position %5ld matches\n",
name, ms, ms * 1e6 / N, m);
}
int main() {
plain.assign(N, 'x');
for (size_t i = 0; i < N; ++i) plain[i] = (char)('a' + (i * 7 + i / 13) % 26);
for (size_t i = 79; i < N; i += 80) plain[i] = '\n';
printf("\n std::regex, texte de %.0f Ko sans chiffre ni 'Z'\n\n", N / 1024.0);
bench("motif complet (19 car., 6 groupes)",
R"((\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}))");
bench("motif complet, sans quantificateur",
R"((\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d))");
bench("motif \\d{4} (quantificateur)", R"(\d{4})");
bench("motif \\d\\d\\d\\d (repete a la main)", R"(\d\d\d\d)");
bench("motif \\d{1} (quantificateur trivial)", R"(\d{1})");
bench("motif \\d (un seul noeud)", R"(\d)");
bench("motif Z (litteral)", R"(Z)");
printf("\n");
return 0;
}