regex_comparison.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef REGEX_COMPARISON_HPP
  12. #define REGEX_COMPARISON_HPP
  13. #include <string>
  14. #include <list>
  15. #include <boost/limits.hpp>
  16. //
  17. // globals:
  18. //
  19. extern bool time_boost;
  20. extern bool time_greta;
  21. extern bool time_safe_greta;
  22. extern bool time_dynamic_xpressive;
  23. extern bool time_static_xpressive;
  24. //extern bool time_posix;
  25. //extern bool time_pcre;
  26. extern bool test_matches;
  27. extern bool test_short_twain;
  28. extern bool test_long_twain;
  29. extern std::string xml_out_file;
  30. extern std::string xml_contents;
  31. int handle_argument(const std::string& what);
  32. int show_usage();
  33. void load_file(std::string& text, const char* file);
  34. void output_xml_results(bool show_description, const std::string& title, const std::string& filename);
  35. struct results
  36. {
  37. double boost_time;
  38. double greta_time;
  39. double safe_greta_time;
  40. double dynamic_xpressive_time;
  41. double static_xpressive_time;
  42. //double posix_time;
  43. //double pcre_time;
  44. double factor;
  45. std::string expression;
  46. std::string description;
  47. results(const std::string& ex, const std::string& desc)
  48. : boost_time(-1),
  49. greta_time(-1),
  50. safe_greta_time(-1),
  51. dynamic_xpressive_time(-1),
  52. static_xpressive_time(-1),
  53. //posix_time(-1),
  54. //pcre_time(-1),
  55. factor((std::numeric_limits<double>::max)()),
  56. expression(ex),
  57. description(desc)
  58. {}
  59. void finalise()
  60. {
  61. if((boost_time >= 0) && (boost_time < factor))
  62. factor = boost_time;
  63. if((greta_time >= 0) && (greta_time < factor))
  64. factor = greta_time;
  65. if((safe_greta_time >= 0) && (safe_greta_time < factor))
  66. factor = safe_greta_time;
  67. if((dynamic_xpressive_time >= 0) && (dynamic_xpressive_time < factor))
  68. factor = dynamic_xpressive_time;
  69. if((static_xpressive_time >= 0) && (static_xpressive_time < factor))
  70. factor = static_xpressive_time;
  71. //if((posix_time >= 0) && (posix_time < factor))
  72. // factor = posix_time;
  73. //if((pcre_time >= 0) && (pcre_time < factor))
  74. // factor = pcre_time;
  75. if((factor >= 0) && (factor < factor))
  76. factor = factor;
  77. }
  78. };
  79. extern std::list<results> result_list;
  80. namespace b {
  81. // boost tests:
  82. double time_match(const std::string& re, const std::string& text);
  83. double time_find_all(const std::string& re, const std::string& text);
  84. }
  85. //namespace posix {
  86. //// posix tests:
  87. //double time_match(const std::string& re, const std::string& text);
  88. //double time_find_all(const std::string& re, const std::string& text);
  89. //
  90. //}
  91. //namespace pcr {
  92. //// pcre tests:
  93. //double time_match(const std::string& re, const std::string& text);
  94. //double time_find_all(const std::string& re, const std::string& text);
  95. //
  96. //}
  97. namespace g {
  98. // greta 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. namespace gs {
  103. // safe greta tests:
  104. double time_match(const std::string& re, const std::string& text);
  105. double time_find_all(const std::string& re, const std::string& text);
  106. }
  107. namespace dxpr {
  108. // dynamic xpressive tests:
  109. double time_match(const std::string& re, const std::string& text);
  110. double time_find_all(const std::string& re, const std::string& text);
  111. }
  112. namespace sxpr {
  113. // static xpressive tests:
  114. double time_match(const std::string& re, const std::string& text);
  115. double time_find_all(const std::string& re, const std::string& text);
  116. }
  117. void test_match(const std::string& re, const std::string& text, const std::string& description);
  118. void test_find_all(const std::string& re, const std::string& text, const std::string& description);
  119. inline void test_match(const std::string& re, const std::string& text)
  120. { test_match(re, text, text); }
  121. inline void test_find_all(const std::string& re, const std::string& text)
  122. { test_find_all(re, text, ""); }
  123. #define REPEAT_COUNT 10
  124. #endif