Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <random>
  5. #include <ctime>
  6. #include <windows.h>
  7. #include "biblioteka.h"
  8.  
  9. using namespace std;
  10.  
  11. double PCFreq = 0.0;
  12. __int64 CounterStart = 0;
  13.  
  14. void StartCounter()
  15. {
  16.     LARGE_INTEGER li;
  17.     if(!QueryPerformanceFrequency(&li))
  18.         cout << "QueryPerformanceFrequency failed!\n";
  19.     PCFreq = double(li.QuadPart)/1000.0;
  20.     QueryPerformanceCounter(&li);
  21.     CounterStart = li.QuadPart;
  22. }
  23.  
  24. double GetCounter()
  25. {
  26.     LARGE_INTEGER li;
  27.     QueryPerformanceCounter(&li);
  28.     return double(li.QuadPart-CounterStart)/PCFreq;
  29. }
  30.  
  31. int main()
  32. {
  33. //    string text;
  34. //    ifstream plik;
  35. //    plik.open("tekst.txt", ios::in);
  36. //    if(plik.is_open())
  37. //    {
  38. //        getline(plik, text);
  39. //        plik.close();
  40. //    }
  41. //    string pattern;
  42. //    cout << "Podaj wzorzec\n> ";
  43. //    getline(cin, pattern);
  44. //    cout << "Podany wzorzec to: " << pattern << endl;
  45. //
  46. //    Search test(text, pattern);
  47. //
  48. //    StartCounter();
  49. //    test.MorrisKnuth();
  50. //    cout << GetCounter() << endl;
  51. //
  52. //    StartCounter();
  53. //    test.Sunday();
  54. //    cout << GetCounter() << endl;
  55. //
  56. //    return 0;
  57.  
  58.     random_device rd;
  59.     mt19937 gen(time(NULL));
  60.     normal_distribution<> dis(77.0, 2.0);
  61.  
  62.     string sunday = "wynikSun.txt";
  63.     ofstream sundayW(sunday.c_str());
  64.     string knuth = "wynikKnuth.txt";
  65.     ofstream knuthW(knuth.c_str());
  66.  
  67.     string pattern;
  68.     double tmp;
  69.     char c1;
  70.  
  71.     for(int i = 0; i < 5; i++)
  72.     {
  73.         tmp = dis(gen);
  74.         if(tmp < 0.0)
  75.             tmp = 0.0;
  76.         if(tmp > 255.0)
  77.             tmp = 255.0;
  78.         c1 = lround(tmp);
  79.         pattern += c1;
  80.     }
  81.  
  82.     for(int h = 0; h < 100; h++) // petla do zliczania sredniej z testow wariancji
  83.     {
  84.         string text;
  85.         double tmp2;
  86.         char c2;
  87.  
  88.         for(int i = 0; i < 100000; i++)
  89.         {
  90.             tmp2 = dis(gen);
  91.             if(tmp2 < 0.0)
  92.                 tmp2 = 0.0;
  93.             if(tmp2 > 255.0)
  94.                 tmp2 = 255.0;
  95.             c2 = lround(tmp2);
  96.             text += c2;
  97.         }
  98.         //cout << "Tekst: " << text << endl;
  99.         //cout << "Wzor: " << pattern << endl;
  100.  
  101.         Search test2(text, pattern);
  102.  
  103.         StartCounter();
  104.         test2.MorrisKnuth();
  105.         //cout << GetCounter() << endl;
  106.         knuthW << GetCounter() << endl;
  107.  
  108.         StartCounter();
  109.         test2.Sunday();
  110.         //cout << GetCounter() << endl;
  111.         sundayW << GetCounter() << endl;
  112.     }
  113.  
  114.  
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement