• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_greta;
25 extern bool time_safe_greta;
26 extern bool time_dynamic_xpressive;
27 extern bool time_static_xpressive;
28 //extern bool time_posix;
29 //extern bool time_pcre;
30 
31 extern bool test_matches;
32 extern bool test_short_twain;
33 extern bool test_long_twain;
34 
35 extern std::string xml_out_file;
36 extern std::string xml_contents;
37 
38 
39 int handle_argument(const std::string& what);
40 int show_usage();
41 void load_file(std::string& text, const char* file);
42 void output_xml_results(bool show_description, const std::string& title, const std::string& filename);
43 
44 struct results
45 {
46    double boost_time;
47    double greta_time;
48    double safe_greta_time;
49    double dynamic_xpressive_time;
50    double static_xpressive_time;
51    //double posix_time;
52    //double pcre_time;
53    double factor;
54    std::string expression;
55    std::string description;
resultsresults56    results(const std::string& ex, const std::string& desc)
57       : boost_time(-1),
58         greta_time(-1),
59         safe_greta_time(-1),
60         dynamic_xpressive_time(-1),
61         static_xpressive_time(-1),
62         //posix_time(-1),
63         //pcre_time(-1),
64         factor((std::numeric_limits<double>::max)()),
65         expression(ex),
66         description(desc)
67    {}
finaliseresults68    void finalise()
69    {
70       if((boost_time >= 0) && (boost_time < factor))
71          factor = boost_time;
72       if((greta_time >= 0) && (greta_time < factor))
73          factor = greta_time;
74       if((safe_greta_time >= 0) && (safe_greta_time < factor))
75           factor = safe_greta_time;
76       if((dynamic_xpressive_time >= 0) && (dynamic_xpressive_time < factor))
77           factor = dynamic_xpressive_time;
78       if((static_xpressive_time >= 0) && (static_xpressive_time < factor))
79           factor = static_xpressive_time;
80       //if((posix_time >= 0) && (posix_time < factor))
81       //   factor = posix_time;
82       //if((pcre_time >= 0) && (pcre_time < factor))
83       //   factor = pcre_time;
84       if((factor >= 0) && (factor < factor))
85          factor = factor;
86    }
87 };
88 
89 extern std::list<results> result_list;
90 
91 
92 namespace b {
93 // boost tests:
94 double time_match(const std::string& re, const std::string& text);
95 double time_find_all(const std::string& re, const std::string& text);
96 }
97 //namespace posix {
98 //// posix tests:
99 //double time_match(const std::string& re, const std::string& text);
100 //double time_find_all(const std::string& re, const std::string& text);
101 //
102 //}
103 //namespace pcr {
104 //// pcre tests:
105 //double time_match(const std::string& re, const std::string& text);
106 //double time_find_all(const std::string& re, const std::string& text);
107 //
108 //}
109 namespace g {
110 // greta tests:
111 double time_match(const std::string& re, const std::string& text);
112 double time_find_all(const std::string& re, const std::string& text);
113 }
114 namespace gs {
115 // safe greta tests:
116 double time_match(const std::string& re, const std::string& text);
117 double time_find_all(const std::string& re, const std::string& text);
118 }
119 namespace dxpr {
120 // dynamic xpressive tests:
121 double time_match(const std::string& re, const std::string& text);
122 double time_find_all(const std::string& re, const std::string& text);
123 }
124 namespace sxpr {
125 // static xpressive tests:
126 double time_match(const std::string& re, const std::string& text);
127 double time_find_all(const std::string& re, const std::string& text);
128 }
129 void test_match(const std::string& re, const std::string& text, const std::string& description);
130 void test_find_all(const std::string& re, const std::string& text, const std::string& description);
test_match(const std::string & re,const std::string & text)131 inline void test_match(const std::string& re, const std::string& text)
132 { test_match(re, text, text); }
test_find_all(const std::string & re,const std::string & text)133 inline void test_find_all(const std::string& re, const std::string& text)
134 { test_find_all(re, text, ""); }
135 
136 
137 #define REPEAT_COUNT 10
138 
139 #endif
140