forked from microsoft/STL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex_match.cpp
More file actions
58 lines (48 loc) · 2.21 KB
/
regex_match.cpp
File metadata and controls
58 lines (48 loc) · 2.21 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
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <benchmark/benchmark.h>
#include <cstddef>
#include <regex>
#include <string>
using namespace std;
using namespace regex_constants;
void bm_match_sequence_of_as(benchmark::State& state, const char* pattern, syntax_option_type syntax = ECMAScript) {
string input(static_cast<size_t>(state.range()), 'a');
regex re{pattern, syntax};
for (auto _ : state) {
benchmark::DoNotOptimize(input);
const char* pos = input.data();
const char* end = input.data() + input.size();
cmatch match;
regex_match(pos, end, match, re);
}
}
void bm_match_sequence_of_9a1b(benchmark::State& state, const char* pattern, syntax_option_type syntax = ECMAScript) {
string input;
for (int i = 0; i < state.range(); ++i) {
input += "aaaaaaaaab";
}
regex re{pattern, syntax};
for (auto _ : state) {
benchmark::DoNotOptimize(input);
const char* pos = input.data();
const char* end = input.data() + input.size();
cmatch match;
regex_match(pos, end, match, re);
}
}
void common_args(auto bm) {
bm->Arg(100)->Arg(200)->Arg(400);
}
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "a*", "a*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "a*?", "a*?")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(?:a)*", "(?:a)*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(a)*", "(a)*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(a)*?", "(a)*?")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(?:b|a)*", "(?:b|a)*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(b|a)*", "(b|a)*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(a)(?:b|a)*", "(a)(?:b|a)*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(a)(b|a)*", "(a)(b|a)*")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_as, "(a)(?:b|a)*c", "(a)(?:b|a)*c")->Apply(common_args);
BENCHMARK_CAPTURE(bm_match_sequence_of_9a1b, "(?:a*b)*", "(?:a*b)*")->Apply(common_args);
BENCHMARK_MAIN();