#include "hashing_algorithms.hpp" #include #include #include /* #include */ #include /* #include */ /* #include */ using namespace std; int main() { unsigned int M = 9299983; unsigned int m = 3226097; unsigned int result; const clock_t begin_time1 = clock(); for (unsigned int y = 0; y < M; y++) { result = (unsigned int) ((float)(y*m)/(float)M); } const clock_t end_time1 = clock(); cout << "Naive time: " << float( end_time1 - begin_time1 ) / CLOCKS_PER_SEC << endl; cout << "Result: " << result << endl; const clock_t begin_time2 = clock(); for (unsigned int y = 0; y < M; y += 10) { result = (unsigned int) ((float)(y*m)/(float)M); result = (unsigned int) ((float)((y+1)*m)/(float)M); result = (unsigned int) ((float)((y+2)*m)/(float)M); result = (unsigned int) ((float)((y+3)*m)/(float)M); result = (unsigned int) ((float)((y+4)*m)/(float)M); result = (unsigned int) ((float)((y+5)*m)/(float)M); result = (unsigned int) ((float)((y+6)*m)/(float)M); result = (unsigned int) ((float)((y+7)*m)/(float)M); result = (unsigned int) ((float)((y+8)*m)/(float)M); result = (unsigned int) ((float)((y+9)*m)/(float)M); } const clock_t end_time2 = clock(); cout << "Naive time (unrolled): " << float( end_time2 - begin_time2 ) / CLOCKS_PER_SEC << endl; cout << "Result: " << result << endl; const clock_t begin_time6 = clock(); for (unsigned int y = 0; y < M; y++) { result = y*m/M; } const clock_t end_time6 = clock(); cout << "Naive time (no-typecasting): " << float( end_time6 - begin_time6 ) / CLOCKS_PER_SEC << endl; cout << "Result: " << result << endl; const clock_t begin_time7 = clock(); for (unsigned int y = 0; y < M; y += 10) { result = y*m/M; result = ((y+1)*m)/M; result = ((y+2)*m)/M; result = ((y+3)*m)/M; result = ((y+4)*m)/M; result = ((y+5)*m)/M; result = ((y+6)*m)/M; result = ((y+7)*m)/M; result = ((y+8)*m)/M; result = ((y+9)*m)/M; } const clock_t end_time7 = clock(); cout << "Naive time (no-typecasting, unrolled): " << float( end_time7 - begin_time7 ) / CLOCKS_PER_SEC << endl; cout << "Result: " << result << endl; float mM = (float) m/(float) M; const clock_t begin_time3 = clock(); for (unsigned int y = 0; y < M; y ++) { result = (unsigned int) (((float) y)*mM); } const clock_t end_time3 = clock(); cout << "Precalculation time: " << float( end_time3 - begin_time3 ) / CLOCKS_PER_SEC << endl; cout << "Result: " << result << endl; const clock_t begin_time4 = clock(); for (unsigned int y = 0; y < M; y += 10) { result = (unsigned int) ((float) y*mM); result = (unsigned int) ((float) (y+1)*mM); result = (unsigned int) ((float) (y+2)*mM); result = (unsigned int) ((float) (y+3)*mM); result = (unsigned int) ((float) (y+4)*mM); result = (unsigned int) ((float) (y+5)*mM); result = (unsigned int) ((float) (y+6)*mM); result = (unsigned int) ((float) (y+7)*mM); result = (unsigned int) ((float) (y+8)*mM); result = (unsigned int) ((float) (y+9)*mM); } const clock_t end_time4 = clock(); cout << "Precalculation time (unrolled): " << float( end_time4 - begin_time4 ) / CLOCKS_PER_SEC << endl; cout << "Result: " << result << endl; /* for (unsigned int y = 0; y < M; y++){ */ /* // Very often, differentiating by multiplying first or dividing first results in the result being off by 1 from each other */ /* /1* if (abs((int) ((float)y*((float)m/(float)M)) - (int) ((float) y*mM)) >= 1) *1/ */ /* /1* cout <<(unsigned int) ((float)y*(float)m/(float)M) << " != " << (unsigned int) ((float) y*mM) << endl; *1/ */ /* /1* if (abs((int)(y*m/M - (y*m)/M)) >= 1) *1/ */ /* /1* cout <