szabivan

Untitled

Feb 2nd, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. // RegexTester.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <iostream>
  7. #include <ctime>
  8.  
  9. #include "re2/re2.h"
  10.  
  11. bool match_an_re2(int n){
  12.     std::string theRegexString;
  13.     std::string theText;
  14.     for (int i = 0; i < n; i++){
  15.         theRegexString = "a?" + theRegexString + "a";
  16.         theText += "a";
  17.     }
  18.  
  19.     clock_t t = clock();
  20.  
  21.     bool ret = RE2::FullMatch(theText, theRegexString);
  22.  
  23.     t = clock() - t;
  24.     std::cout << "Matching (a?)^na^n on a^n for n = " << n << " we get a " << ret << " in " << ((float)t) / CLOCKS_PER_SEC << " seconds." << std::endl;
  25.     return ret;
  26. }
  27.  
  28.  
  29.  
  30. int _tmain(int argc, _TCHAR* argv[])
  31. {
  32.     for (int i = 1; i < 100; i++){
  33.         match_an_re2(i);
  34.     }
  35.     system("PAUSE");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment