1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2002 |
---|
4 | * John Maddock |
---|
5 | * |
---|
6 | * Use, modification and distribution are subject to the |
---|
7 | * Boost Software License, Version 1.0. (See accompanying file |
---|
8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | * |
---|
10 | */ |
---|
11 | |
---|
12 | |
---|
13 | #ifndef REGEX_COMPARISON_HPP |
---|
14 | #define REGEX_COMPARISON_HPP |
---|
15 | |
---|
16 | #include <string> |
---|
17 | #include <list> |
---|
18 | #include <boost/limits.hpp> |
---|
19 | |
---|
20 | // |
---|
21 | // globals: |
---|
22 | // |
---|
23 | extern bool time_boost; |
---|
24 | extern bool time_localised_boost; |
---|
25 | extern bool time_greta; |
---|
26 | extern bool time_safe_greta; |
---|
27 | extern bool time_posix; |
---|
28 | extern bool time_pcre; |
---|
29 | extern bool time_xpressive; |
---|
30 | |
---|
31 | extern bool test_matches; |
---|
32 | extern bool test_short_twain; |
---|
33 | extern bool test_long_twain; |
---|
34 | extern bool test_code; |
---|
35 | extern bool test_html; |
---|
36 | |
---|
37 | extern std::string html_template_file; |
---|
38 | extern std::string html_out_file; |
---|
39 | extern std::string html_contents; |
---|
40 | |
---|
41 | |
---|
42 | int handle_argument(const std::string& what); |
---|
43 | int show_usage(); |
---|
44 | void load_file(std::string& text, const char* file); |
---|
45 | void output_html_results(bool show_description, const std::string& tagname); |
---|
46 | void output_final_html(); |
---|
47 | |
---|
48 | |
---|
49 | struct results |
---|
50 | { |
---|
51 | double boost_time; |
---|
52 | double localised_boost_time; |
---|
53 | double greta_time; |
---|
54 | double safe_greta_time; |
---|
55 | double posix_time; |
---|
56 | double pcre_time; |
---|
57 | double xpressive_time; |
---|
58 | double factor; |
---|
59 | std::string expression; |
---|
60 | std::string description; |
---|
61 | results(const std::string& ex, const std::string& desc) |
---|
62 | : boost_time(-1), |
---|
63 | localised_boost_time(-1), |
---|
64 | greta_time(-1), |
---|
65 | safe_greta_time(-1), |
---|
66 | posix_time(-1), |
---|
67 | pcre_time(-1), |
---|
68 | xpressive_time(-1), |
---|
69 | factor((std::numeric_limits<double>::max)()), |
---|
70 | expression(ex), |
---|
71 | description(desc) |
---|
72 | {} |
---|
73 | void finalise() |
---|
74 | { |
---|
75 | if((boost_time >= 0) && (boost_time < factor)) |
---|
76 | factor = boost_time; |
---|
77 | if((localised_boost_time >= 0) && (localised_boost_time < factor)) |
---|
78 | factor = localised_boost_time; |
---|
79 | if((greta_time >= 0) && (greta_time < factor)) |
---|
80 | factor = greta_time; |
---|
81 | if((safe_greta_time >= 0) && (safe_greta_time < factor)) |
---|
82 | factor = safe_greta_time; |
---|
83 | if((posix_time >= 0) && (posix_time < factor)) |
---|
84 | factor = posix_time; |
---|
85 | if((pcre_time >= 0) && (pcre_time < factor)) |
---|
86 | factor = pcre_time; |
---|
87 | if((xpressive_time >= 0) && (xpressive_time < factor)) |
---|
88 | factor = xpressive_time; |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | extern std::list<results> result_list; |
---|
93 | |
---|
94 | |
---|
95 | namespace b { |
---|
96 | // boost tests: |
---|
97 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
98 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
99 | |
---|
100 | } |
---|
101 | namespace bl { |
---|
102 | // localised boost tests: |
---|
103 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
104 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
105 | |
---|
106 | } |
---|
107 | namespace pcr { |
---|
108 | // pcre tests: |
---|
109 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
110 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
111 | |
---|
112 | } |
---|
113 | namespace g { |
---|
114 | // greta tests: |
---|
115 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
116 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
117 | |
---|
118 | } |
---|
119 | namespace gs { |
---|
120 | // safe greta tests: |
---|
121 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
122 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
123 | |
---|
124 | } |
---|
125 | namespace posix { |
---|
126 | // safe greta tests: |
---|
127 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
128 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
129 | |
---|
130 | } |
---|
131 | namespace dxpr { |
---|
132 | // xpressive tests: |
---|
133 | double time_match(const std::string& re, const std::string& text, bool icase); |
---|
134 | double time_find_all(const std::string& re, const std::string& text, bool icase); |
---|
135 | } |
---|
136 | |
---|
137 | void test_match(const std::string& re, const std::string& text, const std::string& description, bool icase = false); |
---|
138 | void test_find_all(const std::string& re, const std::string& text, const std::string& description, bool icase = false); |
---|
139 | inline void test_match(const std::string& re, const std::string& text, bool icase = false) |
---|
140 | { test_match(re, text, text, icase); } |
---|
141 | inline void test_find_all(const std::string& re, const std::string& text, bool icase = false) |
---|
142 | { test_find_all(re, text, "", icase); } |
---|
143 | |
---|
144 | |
---|
145 | #define REPEAT_COUNT 10 |
---|
146 | |
---|
147 | #endif |
---|
148 | |
---|