[134] | 1 | #include "benchmark.h" |
---|
| 2 | #include "system.h" |
---|
| 3 | #include "stdlib.h" |
---|
| 4 | #include "stdio.h" |
---|
| 5 | #include "stdint.h" |
---|
| 6 | #include "../sort/sort.h" |
---|
| 7 | #include "../common/common.h" |
---|
| 8 | |
---|
| 9 | static uint32_t sort_lock; |
---|
| 10 | |
---|
| 11 | int _benchmark_sort (unsigned int size) |
---|
| 12 | { |
---|
| 13 | printf("\n"); |
---|
| 14 | printf("================================\n"); |
---|
| 15 | printf("Benchmark Sort\n"); |
---|
| 16 | printf("================================\n"); |
---|
| 17 | printf("\n"); |
---|
| 18 | |
---|
| 19 | printf(" * Size : %d\n",size); |
---|
| 20 | |
---|
| 21 | unsigned int* SortArray; |
---|
| 22 | |
---|
| 23 | int cycle_begin, result; |
---|
| 24 | |
---|
| 25 | result = 0; |
---|
| 26 | |
---|
| 27 | int p=procnum(); |
---|
| 28 | |
---|
| 29 | sort_t _sort_type; |
---|
| 30 | const sort_t nb_sort_type = 4; |
---|
| 31 | |
---|
| 32 | for (_sort_type=0; _sort_type < nb_sort_type; _sort_type++) |
---|
| 33 | { |
---|
| 34 | sort_t sort_type = (_sort_type+p)%nb_sort_type; |
---|
| 35 | |
---|
| 36 | printf(" * Algo : %s\n",sort_str(sort_type)); |
---|
| 37 | |
---|
| 38 | printf(" * Init...\n"); |
---|
| 39 | |
---|
| 40 | lock_lock(&sort_lock); |
---|
| 41 | SortArray = (unsigned int*) malloc(size*sizeof(unsigned int)); |
---|
| 42 | lock_unlock(&sort_lock); |
---|
| 43 | |
---|
| 44 | unsigned int seed = p; |
---|
| 45 | int i; |
---|
| 46 | for (i=0; i<size; ++i) |
---|
| 47 | { |
---|
| 48 | seed = seed * 1103515245 + 12345; |
---|
| 49 | SortArray[i] = seed&0xff; |
---|
| 50 | } |
---|
| 51 | printf(" * Sort... \n"); |
---|
| 52 | |
---|
| 53 | cycle_begin = cpu_cycles(); |
---|
| 54 | sort((unsigned int *) (SortArray), (unsigned int) size, sort_type); |
---|
| 55 | int cycle_exec = cpu_cycles()-cycle_begin; |
---|
| 56 | |
---|
| 57 | printf(" * Executed in %d cycles\n",cycle_exec); |
---|
| 58 | |
---|
| 59 | result += cycle_exec; |
---|
| 60 | |
---|
| 61 | printf(" * Verification... "); |
---|
| 62 | |
---|
| 63 | for (i = 1; i < size; i++) |
---|
| 64 | { |
---|
| 65 | /* printf("%d ",SortArray[i-1]); */ |
---|
| 66 | |
---|
| 67 | if (SortArray[i] < SortArray[i-1]) |
---|
| 68 | { |
---|
| 69 | printf("KO !!!\n"); |
---|
| 70 | EXIT(1); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | printf("OK\n"); |
---|
| 74 | |
---|
| 75 | free (SortArray); |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | return result; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | int benchmark_sort (void) { return _benchmark_sort(SORT_SIZE); } |
---|
| 83 | |
---|
| 84 | |
---|