Changeset 140 for trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/soft/benchmark/benchmark_sort.c
- Timestamp:
- Mar 9, 2011, 4:11:43 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/soft/benchmark/benchmark_sort.c
r134 r140 9 9 static uint32_t sort_lock; 10 10 11 int _benchmark_sort (unsigned int size) 11 int _benchmark_sort (sort_t sort_type, 12 unsigned int size) 13 { 14 printf(" * Size : %d\n",size); 15 16 unsigned int* SortArray; 17 18 int cycle_begin; 19 20 int num_cpu=procnum(); 21 22 printf(" * Algo : %s\n",sort_str(sort_type)); 23 24 printf(" * Init...\n"); 25 26 lock_lock(&sort_lock); 27 SortArray = (unsigned int*) malloc(size*sizeof(unsigned int)); 28 lock_unlock(&sort_lock); 29 30 unsigned int seed = num_cpu; 31 int i; 32 for (i=0; i<size; ++i) 33 { 34 seed = seed * 1103515245 + 12345; 35 SortArray[i] = seed&0xff; 36 } 37 printf(" * Sort... \n"); 38 39 cycle_begin = cpu_cycles(); 40 sort((unsigned int *) (SortArray), (unsigned int) size, sort_type); 41 int cycle_exec = cpu_cycles()-cycle_begin; 42 43 printf(" * Executed in %d cycles\n",cycle_exec); 44 45 int result = cycle_exec; 46 47 #if VERIFICATION_SORT 48 printf(" * Verification... "); 49 50 for (i = 1; i < size; i++) 51 { 52 /* printf("%d ",SortArray[i-1]); */ 53 54 if (SortArray[i] < SortArray[i-1]) 55 { 56 printf("KO !!!\n"); 57 EXIT(1); 58 } 59 } 60 printf("OK\n"); 61 #endif 62 63 free (SortArray); 64 65 return result; 66 } 67 68 int _benchmark_sort_all (unsigned int size) 69 { 70 printf("\n"); 71 printf("================================\n"); 72 printf("Benchmark Sort (ALL)\n"); 73 printf("================================\n"); 74 printf("\n"); 75 76 int result = 0; 77 int num_cpu=procnum(); 78 sort_t _sort_type; 79 const sort_t nb_sort_type = 4; 80 81 for (_sort_type=0; _sort_type < nb_sort_type; _sort_type++) 82 result += _benchmark_sort((_sort_type+num_cpu)%nb_sort_type,size); 83 84 return result; 85 } 86 87 int _benchmark_sort_one (sort_t sort_type, 88 unsigned int size) 12 89 { 13 90 printf("\n"); … … 17 94 printf("\n"); 18 95 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; 96 return _benchmark_sort(sort_type,size); 80 97 } 81 98 82 int benchmark_sort (void) { return _benchmark_sort(SORT_SIZE); } 83 84 99 int benchmark_sort_all (void) { return _benchmark_sort_all(SORT_ALL_SIZE); } 100 int benchmark_sort_bubble (void) { return _benchmark_sort_one(SORT_BUBBLE ,SORT_BUBBLE_SIZE ); } 101 int benchmark_sort_insertion (void) { return _benchmark_sort_one(SORT_INSERTION,SORT_INSERTION_SIZE); } 102 int benchmark_sort_selection (void) { return _benchmark_sort_one(SORT_SELECTION,SORT_SELECTION_SIZE); } 103 int benchmark_sort_shell (void) { return _benchmark_sort_one(SORT_SHELL ,SORT_SHELL_SIZE ); }
Note: See TracChangeset
for help on using the changeset viewer.