diff --git a/branch_predict_test/Makefile b/branch_predict_test/Makefile index 0aab384..23c6bed 100644 --- a/branch_predict_test/Makefile +++ b/branch_predict_test/Makefile @@ -1,2 +1,2 @@ build: branch_predict.c - gcc branch_predict.c -O2 -o branch_predict.exe + gcc branch_predict.c -O2 -lssl -lcrypto -o branch_predict.exe diff --git a/branch_predict_test/branch_predict b/branch_predict_test/branch_predict deleted file mode 100755 index e109078..0000000 Binary files a/branch_predict_test/branch_predict and /dev/null differ diff --git a/branch_predict_test/branch_predict.c b/branch_predict_test/branch_predict.c index 10e3d20..47ceebf 100644 --- a/branch_predict_test/branch_predict.c +++ b/branch_predict_test/branch_predict.c @@ -3,6 +3,11 @@ #include #include +////////// +#include +#include +///////// + /* * range of the chars in the randomly generated string * @@ -11,8 +16,13 @@ * */ -#define CHAR_START 33 -#define CHAR_END 127 +#define CHAR_START '1' +#define CHAR_END '9' + +//#define MEASURE_FUNC string_bit_count +//#define MEASURE_FUNC string_bit_count2 +//#define MEASURE_FUNC string_bit_count3 +#define MEASURE_FUNC sha1_int_from_string /* * returns dynamically allocated random string @@ -54,6 +64,9 @@ char** read_strings(const char* fileName, size_t* nRead); * count set bits in string s */ int string_bit_count(char* s); +int string_bit_count2(const char* s); +int string_bit_count3(const char* s); +int sha1_int_from_string(const char* s); /* * returns malloced memory of size memSize @@ -66,6 +79,9 @@ int string_sort_func(const void* a, const void* b); void usage_and_exit(); +#define PRE_STR_HELPER(token) #token +#define PRE_STR(token) PRE_STR_HELPER(token) + void usage_and_exit() { printf("usage\n"); printf(" measure \n"); @@ -96,10 +112,11 @@ int main(int argc, char* argv[]) unsigned long long counter = 0; clock_t t1, t0 = clock(); for(; *p; ++p) { - counter += string_bit_count(*p); + counter += MEASURE_FUNC(*p); } t1 = clock(); printf("measure file: <%s>\n", argv[2]); + printf("measure function: <%s>\n", PRE_STR(MEASURE_FUNC)); printf("counter = %llu\n", counter); printf("time = %lf ms\n", (t1 - t0) / (double) CLOCKS_PER_SEC * 1000.0); @@ -187,6 +204,25 @@ int string_bit_count(char* s) { //printf("count = %d\n", count); return count; } +int string_bit_count3(const char* s) { + static const unsigned char lookup[] ={0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; + int len = strlen(s); + int count = 0; + for(int i=0; i unsorted_sample01.txt -./branch_predict sort unsorted_sample01.txt > issorted_sample01.txt -echo "head of unsorted_sample01.txt" >> output.txt +./branch_predict.exe generate 5000000 4 4 > unsorted_sample01.txt +./branch_predict.exe sort unsorted_sample01.txt > issorted_sample01.txt +echo -e "\nhead of unsorted_sample01.txt" >> output.txt head unsorted_sample01.txt >> output.txt -echo "\n" >> output.txt -./branch_predict measure unsorted_sample01.txt >> output.txt -./branch_predict measure issorted_sample01.txt >> output.txt +echo -e "\n" >> output.txt +./branch_predict.exe measure unsorted_sample01.txt >> output.txt +./branch_predict.exe measure issorted_sample01.txt >> output.txt