#include #include #include #include #include #include // for memcpy #include // for not_equal_to #include #include using std::vector; template < typename T, class Seq , class NotEq > void NaiveMatcher (Seq &data, Seq &pat, bool *tr , int n,int m) { NotEq neq; int r=n-m; for (int s=0;s void NaiveMatcher2 (T* data, T* pat, bool *tr , int n,int m) { NotEq neq; int r=n-m; for (int s=0;s(pow(o,m-1)) % q; int pt=0; int t0=0; int r=n-m; for (int i=0;i=r) { printf("Invalid data\n"); return -1; } int *T=new int[n], *P=new int[m]; bool *TR=new bool[r]; srand(time(NULL)); for (int i=0;i (static_cast (d) * ( rand() / (RAND_MAX + 1.0))); // printf ("T[%d]=%d\n",i,T[i]); } for (int i=0;i T1 (T,T+n), P1 (P,P+m); struct timeval s1, s2; gettimeofday (&s1, NULL); NaiveMatcher, std::not_equal_to >(T1,P1,TR,n,m); gettimeofday (&s2, NULL); printf ("NM: templated time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-NM-t",TR,r); gettimeofday (&s1, NULL); NaiveMatcher2 >(T,P,TR,n,m); gettimeofday (&s2, NULL); printf ("NM: templated without stl time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-NM-t",TR,r); gettimeofday (&s1, NULL); NM(T,P,TR,m,n); gettimeofday (&s2, NULL); printf ("NM: c function time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-NM",TR,r); int q=INT_MAX/d; int h=static_cast(pow(d,m-1)) % q; gettimeofday (&s1, NULL); RKM(T,P,TR,m,n,q,d,h); gettimeofday (&s2, NULL); printf ("RKM: c function time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-RKM",TR,r); delete [] T; delete [] TR; delete [] P; return 0; }