L
This commit is contained in:
Binary file not shown.
+44
-29
@@ -15,12 +15,19 @@ int main(int argc,char **argv) {
|
||||
case '2': // Test Sorts
|
||||
{
|
||||
int n;
|
||||
if(!(argv[1][1]>='a'&&argv[1][1]<='z')) return 0;
|
||||
if(!(argv[1][1]>='a'&&argv[1][1]<='z')){
|
||||
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
|
||||
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
|
||||
return 0;}
|
||||
printf("Write n:");
|
||||
scanf("%d",&n);
|
||||
while(getchar()>'\n');
|
||||
uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n);
|
||||
fill_rand(arr, n);
|
||||
printf("Write n nums:");
|
||||
for (int i = 0;i<n;i++){
|
||||
scanf("%d",&arr[i]);
|
||||
}
|
||||
|
||||
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
|
||||
putchar('\n');
|
||||
|
||||
@@ -42,17 +49,24 @@ int main(int argc,char **argv) {
|
||||
for(int i = 0; i<n;i++)printf("%d ",arr[i]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
|
||||
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
|
||||
return 0;
|
||||
}
|
||||
free(arr);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
case '3':
|
||||
{
|
||||
printf("\n N - %d",(18-1)%24+1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("\nPrint 2(r/h/b/m) to sort or 3 to see var");
|
||||
printf("\n2r - radix\n2h - heap\n2b - bubble\n2m - merge\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -71,37 +85,38 @@ void run_exp(void) {
|
||||
int n = MILLION,end=MILLION,step = 50000;
|
||||
for (;n<=end;n+=step){
|
||||
|
||||
uint32_t *arr = (uint32_t*)malloc(sizeof(uint32_t) * n);
|
||||
|
||||
double tRadTotal = 0;
|
||||
for (int i = 0; i < AVG_TIME_LOOPS; i++) {
|
||||
fill_rand(arr, n);
|
||||
double t = get_time();
|
||||
sort_radix(arr,n);
|
||||
tRadTotal += (get_time() - t);
|
||||
}
|
||||
double tRadRes = tRadTotal / AVG_TIME_LOOPS;
|
||||
|
||||
double tHeapTotal = 0;
|
||||
for (int i = 0; i < AVG_TIME_LOOPS; i++) {
|
||||
fill_rand(arr, n);
|
||||
double t = get_time();
|
||||
sort_heap(arr, n);
|
||||
tHeapTotal += (get_time() - t);
|
||||
}
|
||||
double tHeapRes = tHeapTotal / AVG_TIME_LOOPS;
|
||||
uint32_t *arrA = (uint32_t*)malloc(sizeof(uint32_t) * n);
|
||||
uint32_t *arrB = (uint32_t*)malloc(sizeof(uint32_t) * n);
|
||||
uint32_t *arrC = (uint32_t*)malloc(sizeof(uint32_t) * n);
|
||||
|
||||
double tRadTotal = 0;
|
||||
double tHeapTotal = 0;
|
||||
double tBubblTotal = 0;
|
||||
for (int i = 0; i < AVG_TIME_LOOPS; i++) {
|
||||
fill_rand(arr, n);
|
||||
double t = get_time();
|
||||
sort_bubble(arr,n);
|
||||
tBubblTotal += (get_time() - t);
|
||||
fill_rand(arrA, n);
|
||||
arrC = arrB = arrA;
|
||||
|
||||
double ta = get_time();
|
||||
sort_radix(arrA,n);
|
||||
tRadTotal += (get_time() - ta);
|
||||
|
||||
double tb = get_time();
|
||||
sort_heap(arrB, n);
|
||||
tHeapTotal += (get_time() - tb);
|
||||
|
||||
double tc = get_time();
|
||||
sort_bubble(arrC,n);
|
||||
tBubblTotal += (get_time() - tc);
|
||||
}
|
||||
double tRadRes = tRadTotal / AVG_TIME_LOOPS;
|
||||
double tHeapRes = tHeapTotal / AVG_TIME_LOOPS;
|
||||
double tBubblRes = tBubblTotal / AVG_TIME_LOOPS;
|
||||
|
||||
free(arrA);
|
||||
free(arrB);
|
||||
free(arrC);
|
||||
|
||||
fprintf(f, "%d %f %f %f\n", n, tRadRes, tHeapRes, tBubblRes);
|
||||
free(arr);
|
||||
printf("Sort: %d/%d \r", n, end);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,5 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
run: $(TARGET)
|
||||
./$(TARGET) < input > output
|
||||
@cat output
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR) $(TARGET) output
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user